USE [namedatabase]
GO


/****** Object:  StoredProcedure [dbo].[aaaa]    Script Date: 11/30/2019 7:05:46 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/****** Object:  StoredProcedure [dbo].[aaaa]    Script Date: 04/02/2018 04:12:09 ب.ظ ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


    Declare @procName varchar(500)
    Declare cur cursor 

    For select [name] from sys.objects where type = 'p'
        open cur
                    fetch next from cur into @procName
                    While @@fetch_status = 0
                    begin
                        exec('drop procedure [' + @procName + ']')
                        fetch next from cur into @procName
                    End
                    close cur
                    deallocate cur
GO

Declare @sql NVARCHAR(MAX) = N'';

SELECT @sql = @sql + N' DROP FUNCTION ' 
                   + QUOTENAME(SCHEMA_NAME(schema_id)) 
                   + N'.' + QUOTENAME(name)
FROM sys.objects
WHERE type_desc LIKE '%FUNCTION%';

Exec sp_executesql @sql
GO


--Drop trigger
DECLARE @TriggerName AS VARCHAR(500)
 -- Drop or Delete All Triggers in a Database in SQL Server 
DECLARE DropTrigger CURSOR FOR
  SELECT TRG.name AS TriggerName
  FROM   sys.triggers TRG
         INNER JOIN sys.tables TBL
                 ON TBL.OBJECT_ID = TRG.parent_id 
OPEN DropTrigger
 FETCH Next FROM DropTrigger INTO @TriggerName 
WHILE @@FETCH_STATUS = 0
  BEGIN
      DECLARE @SQL VARCHAR(MAX)=NULL
      SET @SQL='Drop Trigger ' + @TriggerName
      PRINT 'Trigger ::' + @TriggerName
            + ' Droped Successfully'
      EXEC (@SQL)
      PRINT @SQL
      FETCH Next FROM DropTrigger INTO @TriggerName
  END
CLOSE DropTrigger 
DEALLOCATE DropTrigger
GO

ALTER TABLE tblListeDastrasi
ALTER COLUMN fldNameGroup nvarchar(40) COLLATE Persian_100_CI_AS

DELETE FROM [dbo].[tblListeDastrasi]   
GO

print 'Processed 100 total records'
SET IDENTITY_INSERT [dbo].[tblListeDastrasi] OFF


DROP PROCEDURE [dah].[DateToShow]
GO

DROP TRIGGER tgInsertUpdateOnline
GO

DROP TRIGGER [dbo].[tgInsertUpdateTafziliOnline]
GO

DROP PROCEDURE [dah].[DateToShow6Va9Ragham]
GO

DROP PROCEDURE [dah].[DeleteSuperVizor]
GO

DROP PROCEDURE [dah].[HasAmalkardSuperVizor]
GO

DROP PROCEDURE [dah].[HasAmalkardVizitor]
GO

DROP PROCEDURE [dah].[InfoPoorsantVizitor]
GO

DROP PROCEDURE [dah].[LoadSuperVisor]
GO

DROP PROCEDURE [dah].[LoadVaseteArshiveBargashtAzForoosh]
GO

DROP PROCEDURE [dah].[LoadVaseteArshiveForoosh]
GO

DROP PROCEDURE [dah].[LoadVaseteArshiveSanad]
GO

DROP PROCEDURE [dah].[LoadVizitor]
GO

DROP PROCEDURE [dah].[MinMaxDateAnbar]
GO

DROP PROCEDURE [dah].[NameKolMoin]
GO

DROP PROCEDURE [dah].[typeSanad]
GO

DROP PROCEDURE [dah].[Update_SuperVizor]
GO

DROP PROCEDURE [dah].[Update_Vizitor]
GO

CREATE TYPE [dbo].[tpRizeForoosh9] AS TABLE(
	[fldShomareSanad] [bigint] NOT NULL,
	[fldShomareFactor] [bigint] NOT NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeVasete2] [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, 2) NULL,
	[fldFeeKol] [decimal](18, 2) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 2) NULL,
	[fldArzeshAfzode] [decimal](18, 2) NULL,
	[fldDarsadArzeshAfzoode] [int] NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 2) NULL,
	[fldMablaghKhales] [decimal](18, 2) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldDateEngheza] [bigint] NULL,
	[fldEshantion] [nvarchar](13) NULL,
	[fldGhymatMasrafkonande] [decimal](18, 2) NULL,
	[fldCodeMasterEshantion] [nvarchar](20) NULL
)
GO
CREATE TYPE [dbo].[tpRizePishForoosh2] 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,
	[fldDarsadArzeshAfzoode] [int] NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldEshantion] [nvarchar](13) NULL
)
GO
CREATE TYPE [dbo].[tpRizeForoosh8] 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,
	[fldCodeMasterEshantion] [nvarchar](20) NULL
)
GO

CREATE TYPE [dbo].[tblCheckVagozari2] AS TABLE(
	[fldShomareCheck] [nvarchar](30) NULL,
	[fldShomareHesab] [bigint] NULL
)
GO


CREATE TYPE [dbo].[tblCheckDaryafti2] AS TABLE(
	[ID] [int] NULL,
	[fldShomareCheck] [nvarchar](30) NULL,
	[fldShomareHesab] [bigint] NULL,
	[fldDateSarResid] [int] NULL,
	[fldCodeBank] [int] NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nchar](10) NULL
)
GO
CREATE TYPE [dbo].[tblCheckDaryaftiNewer4] AS TABLE(
	[ID] [int] NULL,
	[fldShomareCheck] [nvarchar](30) NULL,
	[fldSayad] [nvarchar](40) NULL,
	[fldShaba] [nvarchar](40) NULL,
	[fldShomareHesab] [bigint] NULL,
	[fldDateSarResid] [int] NULL,
	[fldCodeBank] [int] NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldSharhedaryaft] [nvarchar](70) NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nchar](10) NULL
)
GO

CREATE TYPE [dbo].[dtSanadNew] AS TABLE(
	[fldRadif] [nvarchar](10) NULL,
	[fldDay] [nvarchar](5) NULL,
	[fldMonth] [nvarchar](5) NULL,
	[fldYear] [nvarchar](5) NULL,
	[fldCodeKol] [nvarchar](10) NULL,
	[fldCodeMoin] [nvarchar](10) NULL,
	[fldCodeTafzili] [nvarchar](20) NULL,
	[fldCodeMarkaz1] [nvarchar](10) NULL,
	[fldCodeMarkaz2] [nvarchar](10) NULL,
	[fldBedehkar] [decimal](18, 2) NULL,
	[fldBestankar] [decimal](18, 2) NULL,
	[fldSharh] [nvarchar](max) NULL,
	[fldMoinKamel] [nvarchar](20) NULL,
	[fldCodeNoeTafzili] [nvarchar](5) NULL,
	[fldType] [nvarchar](10) NULL
)
GO

CREATE TYPE [dbo].[dtAghsat] AS TABLE(
	[fldRadif] [bigint] NOT NULL,
	[fldShomareVam] [bigint] NOT NULL,
	[fldDateSarResid] [bigint] NULL,
	[fldMablaghGhest] [decimal](18, 0) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtAghsat-Multi]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[dtAghsat-Multi] AS TABLE(
	[fldRadif] [bigint] NOT NULL,
	[fldShomareVam] [bigint] NOT NULL,
	[fldDateSarResid] [bigint] NULL,
	[fldMablaghGhest] [decimal](18, 4) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtBastanFactorTasvieNashode]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[dtBastanFactorTasvieNashode] AS TABLE(
	[fldShomareFactor] [bigint] NULL,
	[fldMablagheFactor] [bigint] NOT NULL,
	[fldMandeTalabAzFactor] [bigint] NOT NULL,
	[fldMablagheDaryafti] [bigint] NOT NULL,
	[fldMMablagheBargashti] [bigint] NOT NULL,
	[fldMandeTasfieNashode] [bigint] NOT NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtCheckBazPasShode]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[dtCheckBazPasShode] AS TABLE(
	[id] [bigint] NULL,
	[fldRadif] [bigint] NULL,
	[fldShomareCheck] [bigint] NULL,
	[fldShomareHesab] [bigint] NULL,
	[fldCodeSahebeCheck] [bigint] NULL,
	[fldNameSahebeCheck] [nvarchar](100) NULL,
	[fldDateSarResid] [nvarchar](100) NULL,
	[fldCodeBank] [bigint] NULL,
	[fldNameBank] [nvarchar](100) NULL,
	[fldShobe] [nvarchar](100) NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldShomarePass] [bigint] NULL,
	[fldSanad] [bigint] NULL,
	[fldShomareBazPas] [bigint] NULL,
	[fldSanadBazPas] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtCheckPass]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
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/20/2023 12:10:49 ب.ظ ******/
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/20/2023 12:10:49 ب.ظ ******/
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/20/2023 12:10:49 ب.ظ ******/
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/20/2023 12:10:49 ب.ظ ******/
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/20/2023 12:10:49 ب.ظ ******/
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].[dtListeForoosh]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[dtListeForoosh] AS TABLE(
	[fldShomareFactor] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtOldTafzili]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[dtOldTafzili] AS TABLE(
	[fldCodeTafzili] [nvarchar](50) NOT NULL,
	[fldSharheTafzili] [nvarchar](200) NOT NULL,
	[fldNoeHesab] [nvarchar](50) NULL,
	[fldNoe] [nvarchar](50) NULL,
	[fldCodeNoe] [nvarchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtTasfie]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[dtTasfie] AS TABLE(
	[fldShomareFactor] [bigint] NULL,
	[fldShomareDaryaft] [bigint] NULL,
	[fldMablagh] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[dtTasfieVam]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[dtTasfieVam] AS TABLE(
	[fldShomareVam] [bigint] NULL,
	[fldShomareGhest] [bigint] NULL,
	[fldShomareDaryaft] [bigint] NULL,
	[fldMablagh] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[LocationTableType]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[LocationTableType] AS TABLE(
	[LocationName] [nvarchar](50) NULL,
	[CostRate] [int] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tbl1]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[tbl1] AS TABLE(
	[fld1] [varchar](50) NULL,
	[fld2] [varchar](50) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tblCheckDaryafti]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
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/20/2023 12:10:49 ب.ظ ******/
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].[tblCheckDaryaftiNewer]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[tblCheckDaryaftiNewer] AS TABLE(
	[ID] [int] NULL,
	[fldShomareCheck] [bigint] NULL,
	[fldShomareHesab] [bigint] NULL,
	[fldDateSarResid] [int] NULL,
	[fldCodeBank] [int] NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldSharhedaryaft] [nvarchar](70) NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tblCheckDaryaftiNewer2]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[tblCheckDaryaftiNewer2] AS TABLE(
	[ID] [int] NULL,
	[fldShomareCheck] [bigint] NULL,
	[fldShaba] [nvarchar](40) NULL,
	[fldShomareHesab] [bigint] NULL,
	[fldDateSarResid] [int] NULL,
	[fldCodeBank] [int] NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldSharhedaryaft] [nvarchar](70) NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tblCheckDaryaftiNewer3]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[tblCheckDaryaftiNewer3] AS TABLE(
	[ID] [int] NULL,
	[fldShomareCheck] [bigint] NULL,
	[fldSayad] [nvarchar](40) NULL,
	[fldShaba] [nvarchar](40) NULL,
	[fldShomareHesab] [bigint] NULL,
	[fldDateSarResid] [int] NULL,
	[fldCodeBank] [int] NULL,
	[fldShobe] [nvarchar](40) NULL,
	[fldSharhedaryaft] [nvarchar](70) NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldCodeSahebeCheck] [nchar](10) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tblCheckPardakhti]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
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/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[tblCheckVagozari] AS TABLE(
	[fldShomareCheck] [bigint] NULL,
	[fldShomareHesab] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tblDaftarCheck]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
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/20/2023 12:10:49 ب.ظ ******/
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/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[TestEmpType2] AS TABLE(
	[ID] [int] NULL,
	[Name] [varchar](3000) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeForoosh]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
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_Amani]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeForoosh_Amani] 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,
	[fldDateEngheza] [bigint] NULL,
	[fldCodeAnbar] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeForoosh_Amani2]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeForoosh_Amani2] 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,
	[fldDateEngheza] [bigint] NULL,
	[fldCodeAnbar] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeForoosh_Enteghal]    Script Date: 02/20/2023 12:10:49 ب.ظ ******/
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].[tpRizeForoosh_EnteghalNew]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeForoosh_EnteghalNew] 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,
	[fldDateEngheza] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeForoosh4]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeForoosh4] 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, 2) NULL,
	[fldFeeYekCarton] [decimal](18, 2) NULL,
	[fldFeeKol] [decimal](18, 2) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 2) NULL,
	[fldArzeshAfzode] [decimal](18, 2) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 2) NULL,
	[fldMablaghKhales] [decimal](18, 2) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldDateEngheza] [bigint] NULL,
	[fldEshantion] [nvarchar](13) NULL,
	[fldGhymatMasrafkonande] [decimal](18, 2) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeForoosh5]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeForoosh5] 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,
	[fldDateEngheza] [bigint] NULL,
	[fldGhymatMasrafkonande] [decimal](18, 2) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeForoosh6]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeForoosh6] AS TABLE(
	[fldShomareSanad] [bigint] NOT NULL,
	[fldShomareFactor] [bigint] NOT NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeVasete2] [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, 2) NULL,
	[fldFeeKol] [decimal](18, 2) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 2) NULL,
	[fldArzeshAfzode] [decimal](18, 2) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 2) NULL,
	[fldMablaghKhales] [decimal](18, 2) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldDateEngheza] [bigint] NULL,
	[fldEshantion] [nvarchar](13) NULL,
	[fldGhymatMasrafkonande] [decimal](18, 2) NULL
)
GO
CREATE TYPE [dbo].[tpRizeForoosh7] AS TABLE(
	[fldShomareSanad] [bigint] NOT NULL,
	[fldShomareFactor] [bigint] NOT NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeVasete2] [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, 2) NULL,
	[fldFeeKol] [decimal](18, 2) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 2) NULL,
	[fldArzeshAfzode] [decimal](18, 2) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 2) NULL,
	[fldMablaghKhales] [decimal](18, 2) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldDateEngheza] [bigint] NULL,
	[fldEshantion] [nvarchar](13) NULL,
	[fldGhymatMasrafkonande] [decimal](18, 2) NULL,
	[fldCodeMasterEshantion] [nvarchar](10) NULL
)
GO

/****** Object:  UserDefinedTableType [dbo].[tpRizeForooshNew]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeForooshNew] 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,
	[fldDateEngheza] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeForooshNewNew]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeForooshNewNew] 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,
	[fldDateEngheza] [bigint] NULL,
	[fldEshantion] [nvarchar](13) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeForooshNewNewNew]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeForooshNewNewNew] 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, 2) NULL,
	[fldFeeYekCarton] [decimal](18, 2) NULL,
	[fldFeeKol] [decimal](18, 2) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 2) NULL,
	[fldArzeshAfzode] [decimal](18, 2) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 2) NULL,
	[fldMablaghKhales] [decimal](18, 2) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldDateEngheza] [bigint] NULL,
	[fldEshantion] [nvarchar](13) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeKharid]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
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_Amani]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeKharid_Amani] AS TABLE(
	[fldShomareSanad] [bigint] NULL,
	[fldShomareFactor] [bigint] NULL,
	[fldCodeVasete] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldCodeTafzili] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] 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,
	[fldDateEngheza] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeKharid_Enteghal]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
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_EnteghalNew]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeKharid_EnteghalNew] 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,
	[fldDateEngheza] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeKharid_EnteghalNewNew]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeKharid_EnteghalNewNew] 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,
	[fldDateEngheza] [bigint] NULL,
	[fldCodeAnbar] [int] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeKharid_FactorKharid]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
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/20/2023 12:10:50 ب.ظ ******/
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, 2) NULL,
	[fldFeeYekCarton] [decimal](18, 2) NULL,
	[fldFeeKol] [decimal](18, 2) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 2) NULL,
	[fldArzeshAfzode] [decimal](18, 2) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 2) NULL,
	[fldMablaghKhales] [decimal](18, 2) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldHamloNaghl] [bigint] NULL,
	[fldGhymatMasrafkonande] [decimal](18, 2) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeKharid_FactorKharid_Final2]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeKharid_FactorKharid_Final2] 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_FactorKharid_FinalNew]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeKharid_FactorKharid_FinalNew] 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, 2) NULL,
	[fldFeeYekCarton] [decimal](18, 2) NULL,
	[fldFeeKol] [decimal](18, 2) NULL,
	[fldDarsadTakhfif] [decimal](18, 2) NULL,
	[fldMablaghTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 2) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 2) NULL,
	[fldArzeshAfzode] [decimal](18, 2) NULL,
	[fldFeeKolBadAzTakhfif] [decimal](18, 2) NULL,
	[fldMablaghKhales] [decimal](18, 2) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldHamloNaghl] [bigint] NULL,
	[fldGhymatMasrafkonande] [decimal](18, 2) NULL,
	[fldDateEngheza] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeKharid_MojodiEbtedaDoreh]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
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].[tpRizePishForoosh]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizePishForoosh] 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,
	[fldEshantion] [nvarchar](13) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeTolid]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeTolid] AS TABLE(
	[fldShomareSanad] [bigint] NULL,
	[fldShomareTolid] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCartonAvalie] [nvarchar](10) NULL,
	[fldTedadJozAvalie] [decimal](18, 2) NULL,
	[fldTedadCartonNahaei] [nvarchar](10) NULL,
	[fldTedadJozNahaei] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 2) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldDarsdeTakhfif] [decimal](18, 0) NULL,
	[fldMablagheTakhfif] [decimal](18, 0) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeTolid2]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeTolid2] AS TABLE(
	[fldShomareSanad] [bigint] NULL,
	[fldShomareTolid] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCartonAvalie] [nvarchar](10) NULL,
	[fldTedadJozAvalie] [decimal](18, 2) NULL,
	[fldTedadCartonNahaei] [nvarchar](10) NULL,
	[fldTedadJozNahaei] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 2) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldDarsdeTakhfif] [decimal](18, 0) NULL,
	[fldMablagheTakhfif] [decimal](18, 0) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeTolidNew]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeTolidNew] AS TABLE(
	[fldShomareSanad] [bigint] NULL,
	[fldShomareTolid] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCartonAvalie] [nvarchar](10) NULL,
	[fldTedadJozAvalie] [decimal](18, 2) NULL,
	[fldTedadCartonNahaei] [nvarchar](10) NULL,
	[fldTedadJozNahaei] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 2) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldHazineTabdil] [decimal](18, 2) NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpRizeTolidNewNew]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[tpRizeTolidNewNew] AS TABLE(
	[fldShomareSanad] [bigint] NULL,
	[fldShomareTolid] [bigint] NULL,
	[fldCodeUser] [bigint] NULL,
	[fldRadif] [int] NOT NULL,
	[fldCodeAnbar] [bigint] NOT NULL,
	[fldCodeKala] [bigint] NOT NULL,
	[fldSharhKala] [nvarchar](250) NULL,
	[fldTedadCartonAvalie] [nvarchar](10) NULL,
	[fldTedadJozAvalie] [decimal](18, 2) NULL,
	[fldTedadCartonNahaei] [nvarchar](10) NULL,
	[fldTedadJozNahaei] [decimal](18, 2) NULL,
	[fldFeeJoz] [decimal](18, 2) NULL,
	[fldFeeYekCarton] [decimal](18, 0) NULL,
	[fldFeeKol] [decimal](18, 0) NULL,
	[fldFeeVahed1BadAzTakhfif] [decimal](18, 0) NULL,
	[fldFeeVahed2BadAzTakhfif] [decimal](18, 0) NULL,
	[fldMablaghKhales] [decimal](18, 0) NULL,
	[fldType] [nvarchar](20) NULL,
	[fldDate] [bigint] NOT NULL,
	[fldTime] [nvarchar](10) NULL,
	[fldDarsdeTakhfif] [decimal](18, 2) NULL,
	[fldMablagheTakhfif] [decimal](18, 0) NULL,
	[fldDateEngheza] [bigint] NULL
)
GO
/****** Object:  UserDefinedTableType [dbo].[tpSanadEbteda_Ashkas]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
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/20/2023 12:10:50 ب.ظ ******/
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:  UserDefinedTableType [dbo].[ZT_CodeNumbers]    Script Date: 02/20/2023 12:10:50 ب.ظ ******/
CREATE TYPE [dbo].[ZT_CodeNumbers] AS TABLE(
	[CodeNumber] [bigint] NOT NULL
)
GO




/****** Object:  View [dbo].[Join_TblTell_TblTafzili]    Script Date: 01/16/2019 10:35:05 ق.ظ ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[ZF_SplitString] 
( 
    @string NVARCHAR(MAX), 
    @delimiter CHAR(1) 
) 
RETURNS @output TABLE(number bigint 
) 
BEGIN 
 
    DECLARE @start INT, @end INT 
    SELECT @start = 1, @end = CHARINDEX(@delimiter, @string) 
 
    WHILE @start < LEN(@string) + 1 BEGIN 
        IF @end = 0  
            SET @end = LEN(@string) + 1
       
        INSERT INTO @output (number)  
        VALUES(SUBSTRING(@string, @start, @end - @start)) 
        SET @start = @end + 1 
        SET @end = CHARINDEX(@delimiter, @string, @start)
        
    END 
 
    RETURN 
 
END
GO


DROP VIEW [viewFilter_Tbl_Tafsili_in_Form_Enteghal_Kala];
GO

DROP VIEW [Join_TblTell_TblTafzili];
GO

DROP VIEW [lstlistKala];
GO

DROP VIEW [View_2];
GO

DROP VIEW [View_ListAshkhas_In_ReportFactorForosh_AliJahangard];
GO

DROP VIEW [View_TblChap];
GO

DROP VIEW [viewGetAnbarForComboBox];
GO

DROP VIEW [viewGetListEshantionGroupTabalaghtis];
GO

DROP VIEW [viewGetListEshantionTabalaghti];
GO

DROP VIEW [viewGridForoosh];
GO

DROP VIEW [viewListBarcodeKala];
GO

DROP VIEW [viewListKalaInFactorForoosh];
GO

DROP VIEW [viewListKalaInFactorForooshByFldCodeGroup];
GO

DROP VIEW [viewListSmallKala];
GO

DROP VIEW [viewLoadVizitor];
GO

DROP VIEW [viewReportListAshkhasByIN];
GO

DROP VIEW [viewRizeForooshEhsan];
GO

DROP VIEW [viewShowListKala];
GO

DROP VIEW [viewShowListSmallGroupKala];
GO

DROP VIEW [viewtestforoosh];
GO


DROP VIEW [viewtestShomaretel];
GO

DROP VIEW [viwListeCheckHayePasNashode];
GO

/****** Object:  View [dbo].[viewGetListEshantionGroupTabalaghtis2]    Script Date: 5/13/2024 3:29:01 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[viewGetListEshantionGroupTabalaghtis2]
AS
SELECT        dbo.tblEshantionGroupTabaghati2.fldCodeGroupKala, dbo.tblEshantionGroupTabaghati2.fldShomareTabaghe, dbo.tblEshantionGroupTabaghati2.fldTedadForoosh, dbo.tblEshantionGroupTabaghati2.fldCodeGroupKalaEshantion, 
                         dbo.tblGroupKala.fldGroupName AS fldNameGroupKalaEshantion, dbo.tblEshantionGroupTabaghati2.fldTedadEshantion
FROM            dbo.tblEshantionGroupTabaghati2 INNER JOIN
                         dbo.tblGroupKala ON dbo.tblEshantionGroupTabaghati2.fldCodeGroupKalaEshantion = dbo.tblGroupKala.fldGroupId
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[35] 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 = 246
               Bottom = 119
               Right = 416
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblEshantionGroupTabaghati2"
            Begin Extent = 
               Top = 6
               Left = 662
               Bottom = 136
               Right = 900
            End
            DisplayFlags = 280
            TopColumn = 2
         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'viewGetListEshantionGroupTabalaghtis2'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewGetListEshantionGroupTabalaghtis2'
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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,fldAddress ,fldGroupName 
FROM            dbo.tblTafzili
inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId = tblTafzili.fldCodeGroup

GO
/****** Object:  View [dbo].[viewGetAnbarForComboBox]    Script Date: 4/4/2020 10:10:02 AM ******/
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].[viewGetListEshantionGroupTabalaghtis]    Script Date: 4/4/2020 10:10:02 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewGetListEshantionGroupTabalaghtis]
AS
SELECT        dbo.tblEshantionGroupTabaghati.fldCodeGroupKala, dbo.tblEshantionGroupTabaghati.fldShomareTabaghe, dbo.tblEshantionGroupTabaghati.fldTedadForoosh, 
                         dbo.tblEshantionGroupTabaghati.fldCodeKalaEshantion, dbo.tblEshantionGroupTabaghati.fldTedadEshantion, dbo.tblKala.fldNameKala
FROM            dbo.tblEshantionGroupTabaghati INNER JOIN
                         dbo.tblKala ON dbo.tblEshantionGroupTabaghati.fldCodeKalaEshantion = dbo.tblKala.fldCodeKala INNER JOIN
                         dbo.tblGroupKala ON dbo.tblEshantionGroupTabaghati.fldCodeGroupKala = dbo.tblGroupKala.fldGroupId


GO
/****** Object:  View [dbo].[viewGetListEshantionTabalaghti]    Script Date: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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].[viewLoadVizitor]    Script Date: 4/4/2020 10:10:02 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[viewLoadVizitor]
AS
SELECT        dbo.tblTafzili.fldCodeTafzili, dbo.tblTafzili.fldSharheTafzili, dbo.tblTafzili.fldPoorsant, dbo.tblTafzili.fldNoeMohasebePoorsant, 
                         CASE WHEN tblTafzili.fldNoeMohasebePoorsant = 1 THEN 'فروش' WHEN tblTafzili.fldNoeMohasebePoorsant = 2 THEN 'واریز' WHEN tblTafzili.fldNoeMohasebePoorsant
                          = 3 THEN 'هدفمند' END 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) AND (dbo.tblTafzili.fldUnActive = 0)


GO
/****** Object:  View [dbo].[viewReportListAshkhasByIN]    Script Date: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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, dbo.tblKala.fldShenase
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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: 4/4/2020 10:10:02 AM ******/
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

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[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 = "tblEshantionGroupTabaghati"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 220
               Right = 243
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblKala"
            Begin Extent = 
               Top = 6
               Left = 281
               Bottom = 236
               Right = 508
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblGroupKala"
            Begin Extent = 
               Top = 6
               Left = 546
               Bottom = 205
               Right = 716
            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 = 2700
         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'viewGetListEshantionGroupTabalaghtis'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewGetListEshantionGroupTabalaghtis'
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[37] 4[13] 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 = "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 = 186
               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[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 = "tblTafzili"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 265
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblTafzili_1"
            Begin Extent = 
               Top = 6
               Left = 303
               Bottom = 135
               Right = 530
            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'viewLoadVizitor'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @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[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


CREATE FUNCTIOn [dbo].[fn_TablesLastUpdateDate](@Date NVARCHAR(20))

RETURNS @table TABLE(TableName NVARCHAR(40), LastUpdated Datetime)

AS

BEGIN


IF(@Date='') OR (@Date Is Null) OR (@Date='0')

    BEGIN
        INSERT INTO @table
        SELECT TOP 100 PERCENT TABLENAME,LASTUPDATED FROM 
        (
            SELECT  B.NAME AS 'TABLENAME', MAX(STATS_DATE (ID,INDID)) AS LASTUPDATED
            FROM    SYS.SYSINDEXES AS A
                    INNER JOIN SYS.OBJECTS AS B ON A.ID = B.OBJECT_ID
            WHERE   B.TYPE = 'U'  AND STATS_DATE (ID,INDID) IS NOT NULL 
            GROUP BY B.NAME
        ) AS A
        ORDER BY LASTUPDATED DESC
    END
ELSE

    BEGIN
        INSERT INTO @table
        SELECT TOP 100 PERCENT TABLENAME,LASTUPDATED FROM 
        (
            SELECT  B.NAME AS 'TABLENAME', MAX(STATS_DATE (ID,INDID)) AS LASTUPDATED,
                    CONVERT(VARCHAR, MAX(STATS_DATE (ID,INDID)), 103) as Date
            FROM    SYS.SYSINDEXES AS A
                    INNER JOIN SYS.OBJECTS AS B ON A.ID = B.OBJECT_ID
            WHERE   B.TYPE = 'U'  AND STATS_DATE (ID,INDID) IS NOT NULL 
            GROUP BY B.NAME
        ) AS A
        WHERE Date=@Date
        ORDER BY LASTUPDATED DESC
    END
RETURN

END
GO
/****** Object:  UserDefinedFunction [dbo].[ZF_GetAccessableAshkhasCode]    Script Date: 4/5/2020 11:11:37 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create FUNCTION [dbo].[ZF_GetAccessableAshkhasCode]
(	
	-- Add the parameters for the function here
	@userCode bigint
)
RETURNS @output TABLE(fldCode bigint 
) 
begin
  --Declare @value nvarchar(100)
  --set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPASHKHAS')

 Declare @value nvarchar(100)
  --set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPASHKHAS')
  if ( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPASHKHAS') = 'True'
  Begin -- Limitation Active

    declare @groups table(fldCode bigint)
	 insert into @groups(fldCode)
	 select fldGroupCode from tblGroupAshkhasAccess where fldUserCode = @usercode

	 insert into @output(fldCode)
	 select fldCodeTafzili from tblTafzili as t
	 inner join @groups as g on convert(nvarchar(100),t.fldCodeGroup) like convert(nvarchar(100),g.fldCode) + '%'
	 group by fldCodeTafzili
	 order by CONVERT(varchar,fldCodeTafzili )


  End
  else
  Begin -- Limitation DeActive
	insert into @output(fldCode)
	select fldCodeTafzili from tblTafzili
	order by CONVERT(varchar,fldCodeTafzili )
  End

  RETURN 
end
GO
/****** Object:  UserDefinedFunction [dbo].[ZF_GetAccessableGroupAshkhasCode]    Script Date: 4/5/2020 11:11:37 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create FUNCTION [dbo].[ZF_GetAccessableGroupAshkhasCode]
(	
	-- Add the parameters for the function here
	@userCode bigint
)
RETURNS @output TABLE(fldCode bigint 
) 
begin
  --Declare @value nvarchar(100)
  --set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPASHKHAS')

  if (( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPASHKHAS') = 'True')
  Begin -- Limitation Active

		declare @tbl table(fldCode bigint) -- in fact -> fldCodeGroupKala 
		insert @tbl(fldCode)
		select fldGroupCode from tblGroupAshkhasAccess where fldUserCode = @userCode 
		
		insert @output(fldCode)
		select fldGroupId from tblGroupAshkhas 
		where  fldGroupId in(select fldCode from @tbl)
		order by CONVERT(varchar,fldGroupId )

  End
  else
  Begin -- Limitation DeActive

		insert @output(fldCode)
		select fldGroupId from tblGroupAshkhas
		order by CONVERT(varchar,fldGroupId )

  End

  RETURN 
end
GO
/****** Object:  UserDefinedFunction [dbo].[ZF_SplitString]    Script Date: 4/5/2020 11:11:37 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[ZF_SplitString] 
( 
    @string NVARCHAR(MAX), 
    @delimiter CHAR(1) 
) 
RETURNS @output TABLE(number bigint 
) 
BEGIN 
 
    DECLARE @start INT, @end INT 
    SELECT @start = 1, @end = CHARINDEX(@delimiter, @string) 
 
    WHILE @start < LEN(@string) + 1 BEGIN 
        IF @end = 0  
            SET @end = LEN(@string) + 1
       
        INSERT INTO @output (number)  
        VALUES(SUBSTRING(@string, @start, @end - @start)) 
        SET @start = @end + 1 
        SET @end = CHARINDEX(@delimiter, @string, @start)
        
    END 
 
    RETURN 
 
END
GO
/****** Object:  UserDefinedFunction [dbo].[SplitString]    Script Date: 4/5/2020 11:11:37 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[SplitString]
(
  @List     nvarchar(max),
  @Delim    nvarchar(255)
)
RETURNS TABLE WITH SCHEMABINDING
AS
   RETURN ( WITH n(n) AS (SELECT 1 UNION ALL SELECT n+1 
       FROM n WHERE n <= LEN(@List))
       SELECT [Value] = SUBSTRING(@List, n, 
       CHARINDEX(@Delim, @List + @Delim, n) - n)
       FROM n WHERE n <= LEN(@List)
      AND SUBSTRING(@Delim + @List, n, DATALENGTH(@Delim)/2) = @Delim
   );
GO

create proc [dbo].[TomanBerial]
@tedadsefr int,
@strResult nvarchar(10) output
as 

begin
	begin transaction AddRecord
		begin try
			UPDATE tblCheckePardakhti 
SET fldMablagh = fldMablagh * POWER(10, @tedadsefr);

UPDATE tblDaftarcheAghsat 
SET fldMablaghGhest = fldMablaghGhest * POWER(10, @tedadsefr);

UPDATE tbleshantionmablagy 
SET fldprice = fldprice * POWER(10, @tedadsefr);

UPDATE tblFee 
SET fldFee = fldFee * POWER(10, @tedadsefr);

UPDATE tblKala 
SET fldFeeBadAzTakhfif = fldFeeBadAzTakhfif * POWER(10, @tedadsefr),
    fldFeeForoosh = fldFeeForoosh * POWER(10, @tedadsefr),
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr);

UPDATE tblMahdoodeMablagheTakhfif 
SET fldMablaghAz = fldMablaghAz * POWER(10, @tedadsefr),
    fldMablaghTa = fldMablaghTa * POWER(10, @tedadsefr);

UPDATE tblMultiFeeDynamic 
SET fldFee = fldFee * POWER(10, @tedadsefr);

UPDATE tblRizeBargashtAzForoosh 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr), 
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr);

UPDATE tblRizeBargashtAzKharid 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr), 
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr);

UPDATE tblRizeFormooleTolid 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr), 
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldHazineTabdil = fldHazineTabdil * POWER(10, @tedadsefr), 
    fldMablagheTakhfif = fldMablagheTakhfif * POWER(10, @tedadsefr);

UPDATE tblRizeForoosh 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr),  
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr);

UPDATE tblRizeKharid  
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr),  
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr), 
    fldHamloNaghl = fldHamloNaghl * POWER(10, @tedadsefr);

UPDATE tblRizePishForoosh 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr),  
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr);

UPDATE tblRizePishPishForoosh 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr),  
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr);

UPDATE tblRizeTasfie 
SET fldMablagh = fldMablagh * POWER(10, @tedadsefr), 
    fldTakhfif = fldTakhfif * POWER(10, @tedadsefr);

UPDATE tblRizeTasfieVam 
SET fldMablagh = fldMablagh * POWER(10, @tedadsefr);

UPDATE tblRizeTolid 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr),
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldHazineTabdil = fldHazineTabdil * POWER(10, @tedadsefr), 
    fldMablagheTakhfif = fldMablagheTakhfif * POWER(10, @tedadsefr), 
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr);



update tblSodooreSanad
		set fldBedehkar=fldBedehkar *  POWER(10, @tedadsefr),
		fldBestankar=fldBestankar *  POWER(10, @tedadsefr)

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





--شروع اینجا

-- ==================================================
-- PARSIK DATABASE UPDATE SCRIPT (LEGACY SQL SERVER)
-- Date: 2026-01-07 16:27:15
-- ==================================================

-- ===============================================
-- SP: [dbo].[aaaa]
-- ===============================================
IF OBJECT_ID(N'dbo.aaaa', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[aaaa] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[aaaa]

@NameVahed nvarChar(70),
@mmm nvarchar(30),
@IDOutPut int outPut
as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin

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

-- ===============================================
-- SP: [dbo].[AddRecordTanzimatForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.AddRecordTanzimatForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[AddRecordTanzimatForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[AmalkardBankInTblCheckPardakhti]
-- ===============================================
IF OBJECT_ID(N'dbo.AmalkardBankInTblCheckPardakhti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[AmalkardBankInTblCheckPardakhti] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[AmalkardCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.AmalkardCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[AmalkardCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[AmalkardCheck] 
	-- Add the parameters for the stored procedure here
	@ShomareCheck nvarchar(30),
	@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

-- ===============================================
-- SP: [dbo].[AmalkardCheckForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.AmalkardCheckForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[AmalkardCheckForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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.
		if @ShomareDaryaft=0
			begin
				set @amalkard='false'
				return
			end

	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

-- ===============================================
-- SP: [dbo].[AmalkardCheckkharid]
-- ===============================================
IF OBJECT_ID(N'dbo.AmalkardCheckkharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[AmalkardCheckkharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[AmalkardCheckkharid]
	-- Add the parameters for the stored procedure here
	@ShomarePardakht bigint,
	@Amalkard nvarchar(15) output

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
		if @ShomarePardakht=0
		begin
			set @amalkard='false'
			return
		end


	declare @cnt bigint
    -- Insert statements for procedure here
	set @cnt= (Select count(fldSHomareCheck) from tblCheckePardakhti Where fldShomarePardakht=@ShomarePardakht and isnumeric(fldShomarePass)=1 )
	
	IF @cnt>0 
		set @Amalkard ='true'
	else		
		set @Amalkard ='false'
END
GO

-- ===============================================
-- SP: [dbo].[AmalkardeAsnadeRabet]
-- ===============================================
IF OBJECT_ID(N'dbo.AmalkardeAsnadeRabet', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[AmalkardeAsnadeRabet] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[AmalkardeAsnadeRabet]

@CodeVasete2 nvarchar(10),
@CodeTafzili nvarchar(10),
@Datefrom int,
@dateUntil int
as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin

	create table #tblTemp(
	fldCodeHesab nvarchar(10) COLLATE Persian_100_CI_AS,
	fldSharheHesab nvarchar(50)  COLLATE Persian_100_CI_AS,
	fldcodevasete2 nvarchar(10) COLLATE Persian_100_CI_AS,
	fldCodeTafzili nvarchar(10) COLLATE Persian_100_CI_AS,
	fldSharheTafzili nvarchar(50)  COLLATE Persian_100_CI_AS,
	fldSharheRabet  nvarchar(200)  COLLATE Persian_100_CI_AS,
	sumMande bigint
	 
	)

	insert into #tblTemp
		(fldCodeHesab,fldSharheHesab,fldcodevasete2,fldSharheRabet,fldCodeTafzili,fldSharheTafzili,sumMande)
		SELECT fldMoinKamel,'',fldcodevasete2,'',fldCodeTafzili,'',sum(fldBedehkar-fldBestankar) FROM  tblSodooreSanad where fldcodevasete2 is not null and fldcodevasete2<>'' and fldDate between @Datefrom and @dateUntil  group by fldMoinKamel,fldcodevasete2,fldCodeTafzili
		

	if isnumeric(@CodeVasete2 )=1 
		delete #tblTemp where fldcodevasete2<>@CodeVasete2

	if isnumeric(@CodeTafzili )=1 
		delete #tblTemp where fldCodeTafzili<>@CodeTafzili

	

	update #tblTemp set fldSharheHesab=tblKolMoin.fldSharheHesab from tblKolMoin where #tblTemp.fldCodeHesab=tblKolMoin.fldCodeHesab
	update #tblTemp set fldSharheRabet=tblTafzili.fldSharheTafzili from tblTafzili where #tblTemp.fldcodevasete2=tblTafzili.fldCodeTafzili
	update #tblTemp set fldSharheTafzili=tblTafzili.fldSharheTafzili from tblTafzili where #tblTemp.fldCodeTafzili =tblTafzili.fldCodeTafzili



	select fldCodeHesab,fldSharheHesab,fldcodevasete2,fldSharheRabet,fldCodeTafzili,fldSharheTafzili,sumMande from #tblTemp
	
end
GO

-- ===============================================
-- SP: [dbo].[AmalkardeForooshVaVarizeVizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.AmalkardeForooshVaVarizeVizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[AmalkardeForooshVaVarizeVizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[AmalkardeForooshVaVarizeVizitor]

@datefrom nvarchar(15),
@dateuntil nvarchar(15)
as 

IF 1 = 0 BEGIN
 SET FMTONLY OFF
END

begin

	create table #tmp(
		fldCodeVasete nvarchar(20) COLLATE Persian_100_CI_AS,
		fldnameVasete nvarchar(250) COLLATE Persian_100_CI_AS,
		fldJameForoosh decimal(18,2),
		fldJameBargashtAzforoosh decimal(18,2),
		fldJameKhaleseForoosh decimal(18,2),
		fldJameVarizBeBank decimal(18,2),
		fldJameVarizBeSandoogh decimal(18,2),
		frmJamePardakhtBank decimal(18,2),
		frmJamePardakhtSandoogh decimal(18,2),
		frmJameKhaleseVariz decimal(18,2)
	)

	delete #tmp
	declare @KolMoinForoosh nvarchar(10),@KolBank nvarchar(10),@kolsandoogh  nvarchar(10)

	insert into #tmp (fldCodeVasete,fldnameVasete)
			SELECT   dbo.tblTafzili.fldCodeTafzili, dbo.tblTafzili.fldSharheTafzili
							FROM         dbo.tblTafzili INNER JOIN
													 dbo.tblTafzili AS tblTafzili_1 ON dbo.tblTafzili.fldCodeSuperVisor = tblTafzili_1.fldCodeTafzili
							WHERE     (dbo.tblTafzili.fldNoeVizitor = 2) and dbo.tblTafzili.fldUnActive=0

	insert into #tmp (fldCodeVasete,fldnameVasete)
		values ('',N'بدون واسطه')


	execute CodeMoinHesab 'foroosh',@KolMoinForoosh output

	execute CodeKolHesab 'bank',@kolbank output
	
	execute CodeKolHesab 'sandoogh' ,@kolsandoogh output

	--فروش
	update #tmp set fldJameForoosh=tbl1.sumJameForoosh from 
		(select sum(fldbestankar) as sumJameForoosh,fldVasete from tblSodooreSanad where  fldMoinKamel=@KolMoinForoosh and flddate between @datefrom and @dateuntil group by fldVasete) as tbl1
		where #tmp.fldCodeVasete=tbl1.fldVasete


	update #tmp set fldJameForoosh=0 where fldJameForoosh is null

	--برگشت از فروش
		update #tmp set fldJameBargashtAzforoosh=tbl1.sumJameForoosh from 
		(select sum(fldbedehkar) as sumJameForoosh,fldVasete from tblSodooreSanad where  fldMoinKamel=@KolMoinForoosh  and flddate between @datefrom and @dateuntil group by fldVasete) as tbl1
		where #tmp.fldCodeVasete=tbl1.fldVasete

		update #tmp set fldJameBargashtAzforoosh=0 where fldJameForoosh is null



	update #tmp set fldJameKhaleseForoosh=fldJameForoosh-fldJameBargashtAzforoosh
	--بانک
	 update #tmp set fldJameVarizBeBank=tbl1.sumJameForoosh from 
		(select sum(fldbedehkar) as sumJameForoosh,fldVasete from tblSodooreSanad where  fldCodeKol=@kolbank  and flddate between @datefrom and @dateuntil group by fldVasete) as tbl1
		where #tmp.fldCodeVasete=tbl1.fldVasete

		update #tmp set fldJameVarizBeBank=0 where fldJameVarizBeBank is null


	update #tmp set frmJamePardakhtBank=tbl1.sumJameForoosh from 
		(select sum(fldBestankar) as sumJameForoosh,fldVasete from tblSodooreSanad where  fldCodeKol=@kolbank  and flddate between @datefrom and @dateuntil group by fldVasete) as tbl1
		where #tmp.fldCodeVasete=tbl1.fldVasete

		update #tmp set frmJamePardakhtBank=0 where frmJamePardakhtBank is null

	--صندوق
	 update #tmp set fldJameVarizBeSandoogh=tbl1.sumJameForoosh from 
		(select sum(fldbedehkar) as sumJameForoosh,fldVasete from tblSodooreSanad where  fldCodeKol=@kolsandoogh  and flddate between @datefrom and @dateuntil group by fldVasete) as tbl1
		where #tmp.fldCodeVasete=tbl1.fldVasete

		update #tmp set fldJameVarizBeSandoogh=0 where fldJameVarizBeSandoogh is null


	update #tmp set frmJamePardakhtSandoogh=tbl1.sumJameForoosh from 
		(select sum(fldBestankar) as sumJameForoosh,fldVasete from tblSodooreSanad where  fldCodeKol=@kolsandoogh  and flddate between @datefrom and @dateuntil group by fldVasete) as tbl1
		where #tmp.fldCodeVasete=tbl1.fldVasete

		update #tmp set frmJamePardakhtSandoogh=0 where frmJamePardakhtSandoogh is null

	update #tmp set frmJameKhaleseVariz=fldJameVarizBeBank+fldJameVarizBeSandoogh-frmJamePardakhtBank-frmJamePardakhtSandoogh

    select fldCodeVasete ,fldnameVasete ,fldJameForoosh ,fldJameBargashtAzforoosh,fldJameKhaleseForoosh,fldJameVarizBeBank,fldJameVarizBeSandoogh,frmJamePardakhtBank,frmJamePardakhtSandoogh,frmJameKhaleseVariz  from #tmp




	--select * from tblSodooreSanad Where fldsanad=23
end
GO

-- ===============================================
-- SP: [dbo].[AmalkardeRizeAsnadeRabet]
-- ===============================================
IF OBJECT_ID(N'dbo.AmalkardeRizeAsnadeRabet', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[AmalkardeRizeAsnadeRabet] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[AmalkardeRizeAsnadeRabet]

@CodeVasete2 nvarchar(10),
@CodeTafzili nvarchar(10),
@Datefrom int,
@dateUntil int,
@CodeHesab nvarchar(10)
as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin

	create table #tblTemp(
	fldSanad bigint,
	fldCodeHesab nvarchar(10) COLLATE Persian_100_CI_AS,
	fldSharheHesab nvarchar(50)  COLLATE Persian_100_CI_AS,
	fldcodevasete2 nvarchar(10) COLLATE Persian_100_CI_AS,
	fldCodeTafzili nvarchar(10) COLLATE Persian_100_CI_AS,
	fldSharheTafzili nvarchar(50)  COLLATE Persian_100_CI_AS,
	fldSharheRabet  nvarchar(200)  COLLATE Persian_100_CI_AS,
	fldDate int,
	fldDateShow nvarchar(15),
	fldbedehkar bigint,
	fldBestankar bigint
	
	 
	)

	if isnumeric(@CodeHesab)=1 
		insert into #tblTemp
			(fldSanad,fldCodeHesab,fldSharheHesab,fldcodevasete2,fldSharheRabet,fldCodeTafzili,fldSharheTafzili,fldDate,flddateshow,fldbedehkar,fldBestankar)
			SELECT fldSanad, fldMoinKamel,'',fldcodevasete2,'',fldCodeTafzili,'',fldDate,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2),fldBedehkar,fldBestankar FROM  tblSodooreSanad where fldMoinKamel=@CodeHesab and  fldcodevasete2 is not null and fldcodevasete2<>'' and fldDate between @Datefrom and @dateUntil order by flddate -- group by fldMoinKamel,fldcodevasete2,fldCodeTafzili
	else
		insert into #tblTemp
		(fldSanad,fldCodeHesab,fldSharheHesab,fldcodevasete2,fldSharheRabet,fldCodeTafzili,fldSharheTafzili,fldDate,flddateshow,fldbedehkar,fldBestankar)
		SELECT fldSanad,fldMoinKamel,'',fldcodevasete2,'',fldCodeTafzili,'',fldDate,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2),fldBedehkar,fldBestankar FROM  tblSodooreSanad where fldcodevasete2 is not null and fldcodevasete2<>'' and fldDate between @Datefrom and @dateUntil order by flddate -- group by fldMoinKamel,fldcodevasete2,fldCodeTafzili
		

	if isnumeric(@CodeVasete2 )=1 
		delete #tblTemp where fldcodevasete2<>@CodeVasete2

	if isnumeric(@CodeTafzili )=1 
		delete #tblTemp where fldCodeTafzili<>@CodeTafzili

	

	update #tblTemp set fldSharheHesab=tblKolMoin.fldSharheHesab from tblKolMoin where #tblTemp.fldCodeHesab=tblKolMoin.fldCodeHesab
	update #tblTemp set fldSharheRabet=tblTafzili.fldSharheTafzili from tblTafzili where #tblTemp.fldcodevasete2=tblTafzili.fldCodeTafzili
	update #tblTemp set fldSharheTafzili=tblTafzili.fldSharheTafzili from tblTafzili where #tblTemp.fldCodeTafzili =tblTafzili.fldCodeTafzili



	select fldSanad,fldCodeHesab,fldSharheHesab,fldcodevasete2,fldSharheRabet,fldCodeTafzili,fldSharheTafzili,fldDate,flddateshow,fldbedehkar,fldBestankar from #tblTemp
	
end
GO

-- ===============================================
-- SP: [dbo].[Amalkardesefareshat]
-- ===============================================
IF OBJECT_ID(N'dbo.Amalkardesefareshat', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Amalkardesefareshat] AS BEGIN SET NOCOUNT ON; END')
END
GO

--شروع اینجا
Alter proc [dbo].[Amalkardesefareshat]
@datefrom int,
@dateuntil int,
@CodeVisitor nvarchar(10)
as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin

create Table #tblTemp(
	fldCodeSuperVisor nvarchar(10),
	fldNameSupervisor nvarchar(200),
	fldCodevizitor nvarchar(10),
	fldNameVisitor nvarchar(200),
	fldTedadeSefaresh bigint,
	fldTedadjoz	bigint,
	fldtedadeKol	bigint,
	sumForoosh bigint
	)
	insert #tblTemp (fldCodevizitor,fldNameVisitor, fldCodeSuperVisor,fldNameSupervisor)
					SELECT   dbo.tblTafzili.fldCodeTafzili, dbo.tblTafzili.fldSharheTafzili, dbo.tblTafzili.fldCodeSuperVisor AS CodeSuperVisor, tblTafzili_1.fldSharheTafzili AS fldNameSuperVizor
					FROM         dbo.tblTafzili INNER JOIN
											 dbo.tblTafzili AS tblTafzili_1 ON dbo.tblTafzili.fldCodeSuperVisor = tblTafzili_1.fldCodeTafzili
					WHERE     (dbo.tblTafzili.fldNoeVizitor = 2 and tblTafzili.fldUnActive=0)  order by dbo.tblTafzili.fldUnActive 

--delete #tblTemp
--select * from #tblTemp

update #tblTemp set fldTedadeSefaresh=tbl2.cnt from 
	(select count(fldShomareFactor) as cnt,fldCodeVasete from 
	(select distinct fldShomareFactor,fldCodeVasete from tblRizePishPishForoosh where flddate between @datefrom and @dateuntil ) as tbl1  
	group by fldCodeVasete ) as tbl2
	where #tblTemp.fldCodevizitor=tbl2.fldCodeVasete 
	

update #tblTemp set fldTedadeSefaresh=0 where  fldTedadeSefaresh is null



update #tblTemp set fldTedadJoz=tbl2.sum1 from 
	(select sum(fldTedadJoz) as sum1,fldCodeVasete from 
	(select fldCodeVasete,fldTedadJoz from tblRizePishPishForoosh where flddate between @datefrom and @dateuntil ) as tbl1  
	group by fldCodeVasete ) as tbl2
	where #tblTemp.fldCodevizitor=tbl2.fldCodeVasete 


--update #tblTemp set fldTedadJoz=tbl1.sum1 from 
--	(select distinct sum(fldTedadJoz) as sum1,fldCodeVasete from tblRizePishPishForoosh where flddate between 14040918 and 14040918 group by fldCodeVasete) as tbl1
--	where #tblTemp.fldCodevizitor=tbl1.fldCodeVasete

--update #tblTemp set fldTedadJoz=0 where  fldTedadJoz is null


	--select * from tblRizePishPishForoosh  where flddate between 14040918 and 14040918 and fldCodeVasete=11666


--update #tblTemp set fldTedadJoz=tbl1.sum1 from 
--	(select distinct sum(fldTedadJoz) as sum1,fldCodeVasete from tblRizePishPishForoosh where flddate between 14040918 and 14040918 group by fldCodeVasete) as tbl1
--	where #tblTemp.fldCodevizitor=tbl1.fldCodeVasete


	update #tblTemp set fldtedadeKol=tbl3.sum1 from 
	(select sum(convert(dec,TedadeKol)) as sum1,fldCodeVasete from
	(SELECT 
		LEFT(fldTedadCarton, CHARINDEX('-', fldTedadCarton) - 1) AS TedadeKol,fldCodeVasete
	FROM 
		tblRizePishPishForoosh
	WHERE 
		CHARINDEX('-', fldTedadCarton) > 0 and flddate between @datefrom and 14040918) as tbl2
		group by fldCodeVasete) as tbl3
		where #tblTemp.fldCodevizitor=tbl3.fldCodeVasete


	update #tblTemp set fldtedadeKol=0 where  fldtedadeKol is null
	

	update #tblTemp set sumForoosh=tbl1.sum1 from 
		(select distinct sum(fldMablaghKhales) as sum1,fldCodeVasete from tblRizePishPishForoosh where flddate between @datefrom and @dateuntil group by fldCodeVasete) as tbl1
		where #tblTemp.fldCodevizitor=tbl1.fldCodeVasete

	update #tblTemp set sumForoosh=0 where  sumForoosh is null


	select 	fldCodeSuperVisor,fldNameSupervisor,fldCodevizitor,	fldNameVisitor,fldTedadeSefaresh ,fldTedadjoz,fldtedadeKol,sumForoosh from #tblTemp
	--insert into #tblTemp (fldCodeSuperVisor,fldNameSupervisor,fldCodevizitor,fldNameVisitor,fldTedadeSefaresh,fldTedadejoz,fldtedadeKol)
	--	select '','','',fldCodeVasete, from tblRizePishPishForoosh where flddate between 14040918 and 14040918
	
end
GO

-- ===============================================
-- SP: [dbo].[AmalkardeVizitor3]
-- ===============================================
IF OBJECT_ID(N'dbo.AmalkardeVizitor3', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[AmalkardeVizitor3] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[AmalkardeVizitor3]
--@NameHesab nvarChar(50),
@ListCodeKala varchar(5000)=null,
@ListGroupKala varchar(5000)=null,
@CodeVasete bigint,
@DateFrom nvarchar(10),
@dateTa nvarchar(10)


as
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
begin
	--set @Meghdar=1020
	create table #tblTemp(
		CodeKala bigint,
		Codegrooh bigint,
		NameGorooh nvarchar(200),
		NameKala nvarchar(200),
		TedadFactor bigint,
		TedadForooshJoz decimal(18,2),
		TedadDarKarton decimal(18,2),
		TedadForooshKarton decimal(18,2),
		MablaghForoosh decimal(18,2),
		TedadFactorBargasht bigint,
		TedadBargashtAzForooshJoz decimal(18,2),
		TedadBargashtAzForooshKol decimal(18,2),
		MablaghBargashti decimal(18,2),
		TedadKhalesjoz decimal(18,2),
		TedadKhalsekol decimal(18,2),
		MablagheKhaleseForoosh decimal(18,2)
	)

	delete #tblTemp
	insert into #tblTemp
		(CodeKala,Codegrooh,NameKala,TedadDarKarton)
		Select fldCodeKala,fldCodeGroup,fldNameKala,fldTedadJoz from tblKala

	update #tblTemp set NameGorooh= tblGroupKala.fldGroupName from tblGroupKala where #tblTemp.Codegrooh=tblGroupKala.fldGroupId

		--Select distinct fldShomareFactor from tblRizeForoosh where fldCodeVasete=11172
	if @CodeVasete=0 --همه ویزیتورها
		update #tblTemp set  TedadFactor=tbl1.cntFactor from 
			(Select   fldCodeKala,count(distinct fldShomareFactor) as cntFactor from tblRizeForoosh where flddate between @DateFrom and @dateTa group by fldcodekala) as tbl1
			where tbl1.fldCodeKala=#tblTemp.CodeKala
	else
		update #tblTemp set  TedadFactor=tbl1.cntFactor from 
			(Select   fldCodeKala,count(distinct fldShomareFactor) as cntFactor from tblRizeForoosh where fldCodeVasete=@CodeVasete and flddate between @DateFrom and @dateTa group by fldcodekala) as tbl1
			where tbl1.fldCodeKala=#tblTemp.CodeKala

	if @CodeVasete=0 --همه ویزیتورها
		update #tblTemp set  TedadFactorBargasht=tbl1.cntFactor from 
			(Select   fldCodeKala,count(distinct fldShomareFactor) as cntFactor from tblRizeBargashtAzForoosh where fldCodeVasete=@CodeVasete and flddate between @DateFrom and @dateTa group by fldcodekala) as tbl1
			where tbl1.fldCodeKala=#tblTemp.CodeKala
	else
		update #tblTemp set  TedadFactorBargasht=tbl1.cntFactor from 
			(Select   fldCodeKala,count(distinct fldShomareFactor) as cntFactor from tblRizeBargashtAzForoosh where flddate between @DateFrom and @dateTa group by fldcodekala) as tbl1
			where tbl1.fldCodeKala=#tblTemp.CodeKala

	update #tblTemp set  TedadFactorBargasht=0 where TedadFactorBargasht Is NULL

	update #tblTemp set TedadFactor=0 Where TedadFactor Is NULL

	if @CodeVasete=0 --همه ویزیتورها
		update #tblTemp set  TedadForooshJoz=tbl2.sumTedadJoz from 
			(select sum(fldTedadjoz) as sumTedadJoz ,fldcodekala from tblRizeForoosh where  flddate between @DateFrom and @dateTa  group by fldcodekala) as tbl2
			where #tblTemp.CodeKala=tbl2.fldCodeKala
	else
		update #tblTemp set  TedadForooshJoz=tbl2.sumTedadJoz from 
			(select sum(fldTedadjoz) as sumTedadJoz ,fldcodekala from tblRizeForoosh where fldCodeVasete=@CodeVasete  and flddate between @DateFrom and @dateTa  group by fldcodekala) as tbl2
			where #tblTemp.CodeKala=tbl2.fldCodeKala

	update #tblTemp set TedadForooshJoz=0 Where TedadForooshJoz Is NULL

	if @CodeVasete=0 --همه ویزیتورها
		update #tblTemp set  TedadBargashtAzForooshJoz=tbl2.sumTedadJoz from 
			(select sum(fldTedadjoz) as sumTedadJoz ,fldcodekala from tblRizeBargashtAzForoosh where flddate between @DateFrom and @dateTa  group by fldcodekala) as tbl2
			where #tblTemp.CodeKala=tbl2.fldCodeKala
	else
		update #tblTemp set  TedadBargashtAzForooshJoz=tbl2.sumTedadJoz from 
			(select sum(fldTedadjoz) as sumTedadJoz ,fldcodekala from tblRizeBargashtAzForoosh where fldCodeVasete=@CodeVasete  and flddate between @DateFrom and @dateTa  group by fldcodekala) as tbl2
			where #tblTemp.CodeKala=tbl2.fldCodeKala

	update #tblTemp set TedadBargashtAzForooshJoz=0 Where TedadBargashtAzForooshJoz Is NULL


	if @CodeVasete=0 --همه ویزیتورها
		update #tblTemp set  TedadBargashtAzForooshJoz=tbl2.sumTedadJoz from 
				(select sum(fldTedadjoz) as sumTedadJoz ,fldcodekala from tblRizeBargashtAzForoosh where  flddate between @DateFrom and @dateTa  group by fldcodekala) as tbl2
				where #tblTemp.CodeKala=tbl2.fldCodeKala
	else
		update #tblTemp set  TedadBargashtAzForooshJoz=tbl2.sumTedadJoz from 
				(select sum(fldTedadjoz) as sumTedadJoz ,fldcodekala from tblRizeBargashtAzForoosh where fldCodeVasete=@CodeVasete  and flddate between @DateFrom and @dateTa  group by fldcodekala) as tbl2
				where #tblTemp.CodeKala=tbl2.fldCodeKala

	update #tblTemp set TedadBargashtAzForooshJoz=0 Where TedadBargashtAzForooshJoz Is NULL
	
	
	update #tblTemp set  TedadForooshKarton=round(TedadForooshJoz/TedadDarKarton,0) Where TedadDarKarton<>0
	update #tblTemp set TedadForooshKarton=0 Where TedadForooshKarton Is NULL


	update #tblTemp set  TedadBargashtAzForooshKol=round(TedadBargashtAzForooshJoz/TedadDarKarton,0) Where TedadDarKarton<>0
	update #tblTemp set TedadBargashtAzForooshKol=0 Where TedadBargashtAzForooshKol Is NULL
	

	update #tblTemp set TedadKhalesjoz  =TedadForooshJoz-TedadBargashtAzForooshJoz
	update #tblTemp set TedadKhalsekol  =TedadForooshKarton-TedadBargashtAzForooshKol


	if @CodeVasete=0 --همه ویزیتورها
		update #tblTemp set  MablaghForoosh=tbl3.SumMablagh from 
			(Select Sum(fldMablaghKhales) as SumMablagh,fldCodeKala from tblRizeForoosh where  flddate between @DateFrom and @dateTa  group by fldcodekala ) as tbl3
			where #tblTemp.CodeKala=tbl3.fldCodeKala
	else
		update #tblTemp set  MablaghForoosh=tbl3.SumMablagh from 
			(Select Sum(fldMablaghKhales) as SumMablagh,fldCodeKala from tblRizeForoosh where fldCodeVasete=@CodeVasete  and flddate between @DateFrom and @dateTa  group by fldcodekala ) as tbl3
			where #tblTemp.CodeKala=tbl3.fldCodeKala

	update #tblTemp set  MablaghForoosh=0 Where MablaghForoosh is null


	if @CodeVasete=0 --همه ویزیتورها
		update #tblTemp set  MablaghBargashti=tbl3.SumMablagh from 
			(Select Sum(fldMablaghKhales) as SumMablagh,fldCodeKala from tblRizeBargashtAzForoosh where  flddate between @DateFrom and @dateTa  group by fldcodekala ) as tbl3
			where #tblTemp.CodeKala=tbl3.fldCodeKala
	else
		update #tblTemp set  MablaghBargashti=tbl3.SumMablagh from 
			(Select Sum(fldMablaghKhales) as SumMablagh,fldCodeKala from tblRizeBargashtAzForoosh where fldCodeVasete=@CodeVasete  and flddate between @DateFrom and @dateTa  group by fldcodekala ) as tbl3
			where #tblTemp.CodeKala=tbl3.fldCodeKala

	update #tblTemp set  MablaghBargashti=0 where MablaghBargashti is null

	update #tblTemp set MablagheKhaleseForoosh=MablaghForoosh-MablaghBargashti


	
	if @ListCodeKala<>''
		  begin
		   declare @StrDeleteKala varchar(5000)
		    set  @StrDeleteKala='delete from #tblTemp 
		            where CodeKala NOT IN ('+ @ListCodeKala +')'
					execute(@StrDeleteKala)
		  end

		  if @ListGroupKala<>''
		   begin
		     declare @StrDeleteGroupKala varchar(5000)
		       set  @StrDeleteGroupKala='delete from #tblTemp 
		            where '+ @ListGroupKala + ''
					execute(@StrDeleteGroupKala)
		   end

	 select CodeKala ,Codegrooh,NameGorooh,NameKala ,TedadFactor ,TedadForooshJoz ,TedadDarKarton ,TedadForooshKarton ,MablaghForoosh,TedadFactorBargasht,TedadBargashtAzForooshJoz ,TedadBargashtAzForooshKol ,MablaghBargashti,TedadKhalesjoz,TedadKhalsekol,MablagheKhaleseForoosh  from #tblTemp

end
GO

-- ===============================================
-- SP: [dbo].[anbardar]
-- ===============================================
IF OBJECT_ID(N'dbo.anbardar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[anbardar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[anbardar]

as 

begin

	SELECT fldCodeTafzili,fldSharheTafzili FROM tblTafzili where fldCodeNoe = '0'
	
end
GO

-- ===============================================
-- SP: [dbo].[BahayeTamamShodeForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.BahayeTamamShodeForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[BahayeTamamShodeForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[BahayeTamamShodeForoosh]
@lngDateFrom bigint,
@lngDateUntil bigint

as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END

begin

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
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) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20) COLLATE Persian_100_CI_AS
)


create table #TempMojoodieAnbarForoosh(

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
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) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20) COLLATE Persian_100_CI_AS
)

create table #TempShowMojoodiForoosh(

fldCodeKala bigint,
SumVorood decimal(18, 0),
SumKhorooj decimal(18, 0),
SumMande decimal(18, 0),
BahayeTamamShode decimal(18, 0),
fldTedadDarKarton decimal(18, 0),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadVoroodKarton decimal(18, 0),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadKhoroojKarton decimal(18, 0),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh decimal(18, 0),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldKharid bigint,
fldArzesheMojoodi bigint
)

create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 0),
SumKhorooj decimal(18, 0),
SumMande decimal(18, 0),
fldTedadDarKarton decimal(18, 0),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadVoroodKarton decimal(18, 0),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadKhoroojKarton decimal(18, 0),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh decimal(18, 0),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldKharid bigint,
fldArzesheMojoodi bigint
)

delete #TempMojoodieAnbar
delete #TempMojoodieAnbarForoosh
delete #TempShowMojoodiForoosh
delete #TempShowMojoodi

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 #TempMojoodieAnbarForoosh
                         (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 #TempMojoodieAnbarForoosh
                         (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, fldCodeKala,    fldKharid)
SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
                          fldCodeKala,0
						 FROM            #TempMojoodieAnbar
GROUP BY fldCodeKala



delete #TempMojoodieAnbarForoosh where fldDate<@lngDateFrom 
delete #TempMojoodieAnbarForoosh where fldDate>@lngDateUntil


Insert into #TempShowMojoodiForoosh
	(SumVorood,SumKhorooj,SumMande, fldCodeKala,fldKharid)
SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande,fldCodeKala,0
FROM            #TempMojoodieAnbarForoosh
GROUP BY fldCodeKala




--set @MiangineKharid=0


update #TempShowMojoodi set fldKharid=tbl1.Miangin from
(SELECT        ROUND(SUM(fldFeeVahed1BadAzTakhfif*fldTedadJoz) / SUM(fldTedadJoz), 0) AS Miangin, fldCodeKala
FROM            tblRizeKharid
GROUP BY fldCodeKala
having  SUM(fldTedadJoz)>0
) as tbl1
where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala



update #TempShowMojoodiForoosh set BahayeTamamShode=-1*(#TempShowMojoodi.fldKharid*#TempShowMojoodiForoosh.SumMande) from #TempShowMojoodi
	where #TempShowMojoodiForoosh.fldCodeKala=#TempShowMojoodi.fldCodeKala


Select SUM(BahayeTamamShode) as SumBahayeTamamShodeForooshrafte from #TempShowMojoodiForoosh

--select * from #TempShowMojoodiForoosh
----موجودی مثبت
--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

-- ===============================================
-- SP: [dbo].[bbbb]
-- ===============================================
IF OBJECT_ID(N'dbo.bbbb', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[bbbb] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[bbbb]
--@NameHesab nvarChar(50),
@Meghdar bigint OutPut


as

begin
	--set @Meghdar=1020
	--14041003-2
	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

-- ===============================================
-- SP: [dbo].[ChangeCodeKala]
-- ===============================================
IF OBJECT_ID(N'dbo.ChangeCodeKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ChangeCodeKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ChangeCodeKala]
	@CodeOld bigint,
	@CodeNew bigint,

	@strResult nvarchar(25) output
AS



BEGIN

	begin transaction AddRecord
		begin try
			
			INSERT INTO tblKala
                         ( fldNameKala, fldCodeKala, fldSerial, fldCodeGroup, fldCodeVahed1, fldCodeVahed2, fldNogheSefaresh, fldSharh, fldTedadJoz, fldFeeDarsadKharid, fldFeeBadAzTakhfif, fldNerkhePorsantKol, fldNerkhePorsantJoz, 
                         fldFeeForoosh, fldPathPic, fldGhymatMasrafkonande, fldIDPrinter, fldDateUpdate, flArzesheAfzoode, fldShenase, fldFeeMain, fldCodeOld)
			select  fldNameKala, @CodeNew, fldSerial, fldCodeGroup, fldCodeVahed1, fldCodeVahed2, fldNogheSefaresh, fldSharh, fldTedadJoz, fldFeeDarsadKharid, fldFeeBadAzTakhfif, fldNerkhePorsantKol, fldNerkhePorsantJoz, 
                         fldFeeForoosh, fldPathPic, fldGhymatMasrafkonande, fldIDPrinter, fldDateUpdate, flArzesheAfzoode, fldShenase, fldFeeMain, fldCodeOld from tblkala where fldcodekala=@CodeOld

			

			
			update tblEshantionGroupTabaghati set fldCodeKalaEshantion=@CodeNew where fldCodeKalaEshantion=@CodeOld
			update tblEshantionGroupTekrarShavande set fldCodeKalaEshantion=@CodeNew where fldCodeKalaEshantion=@CodeOld
			update tbleshantionmablagy set fldcodekala=@CodeNew where fldcodekala=@CodeOld			
			update tblEshantionTabaghati set fldCodeKalaForoosh=@CodeNew where fldCodeKalaForoosh=@CodeOld
			update tblEshantionTabaghati set fldCodeKalaEshantion=@CodeNew where fldCodeKalaEshantion=@CodeOld
			update tblEshantionTekrarShavande set fldCodeKalaForoosh=@CodeNew where fldCodeKalaForoosh=@CodeOld
			update tblEshantionTekrarShavande set fldCodeKalaEshantion=@CodeNew where fldCodeKalaEshantion=@CodeOld
			update tblFee set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblIDChapgarKala set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblImageKala set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblListPorsantVaset set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblMahdoodeDarsadTakhfif set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblMahdoodeMablagheTakhfif set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblMoghayratMojoodieAnbar set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblMultiFeeDynamic set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			--update tblMultiFeeDynamicTemp set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblRizeBargashtAzForoosh set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblRizeBargashtAzKharid set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblRizeFormooleTolid set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblRizeForoosh set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblRizeForooshFastFood set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblRizeKharid set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblRizePishForoosh set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblRizePishPishForoosh set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblRizeTolid set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblSefareshGardeshKala set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblTarheTakhfifHajmi set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld

			--update tblkala set fldCodeKala=@CodeNew where fldCodeKala=@CodeOld
			update tblkala set fldCodeOld=@CodeOld where fldCodeKala=@CodeNew

			delete tblKala where fldCodeKala=@CodeOld
				commit transaction AddRecord;
		
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult='error'
				rollback transaction AddRecord;
			end
		end catch
END
GO

-- ===============================================
-- SP: [dbo].[ChangeCodetafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.ChangeCodetafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ChangeCodetafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ChangeCodetafzili]

@OldCode nvarchar(10),
@NewCode nvarchar(10),
@NoeKhata nvarchar(20) output
as 




begin
	begin transaction transact
		begin try

				update tblBaskool set  fldRanande=@NewCode where fldRanande=@OldCode
				update tblBaskool set  fldCodeKharidar=@NewCode where fldCodeKharidar=@OldCode
				update tblCheckeDaryafti set  fldCodeSahebeCheck=@NewCode where fldCodeSahebeCheck=@OldCode
				update tblCheckeDaryafti set  fldVasete=@NewCode where fldVasete=@OldCode
				update tblCheckePardakhti set  fldCodeSahebeCheck=@NewCode where fldCodeSahebeCheck=@OldCode
				update tblCheckePardakhti set  fldCodeSahebeHesab=@NewCode where fldCodeSahebeHesab=@OldCode
				update tblCheckePardakhti set  fldVasete=@NewCode where fldVasete=@OldCode
				update tblDaftarcheTell set  fldCodeTafzili=@NewCode where fldCodeTafzili=@OldCode
				update tblDaryaft set  fldCodeTafzili=@NewCode where fldCodeTafzili=@OldCode
				update tblHavaleGoroohi set  fldCodeRanande=@NewCode where fldCodeRanande=@OldCode
				update tblKarkardeMahane set  fldCodePersonel=@NewCode where fldCodePersonel=@OldCode
				update tblMoarefiePersonel set  fldCodePersonel=@NewCode where fldCodePersonel=@OldCode
				update tblPardakht set  fldCodeTafzili=@NewCode where fldCodeTafzili=@OldCode
				update tblPayeSanavat set  fldCodePersonel=@NewCode where fldCodePersonel=@OldCode
				update tblPorsantVisitor set  fldCodeVisitor=@NewCode where fldCodeVisitor=@OldCode
				update tblRizeBargashtAzForoosh set  fldCodeVasete=@NewCode where fldCodeVasete=@OldCode
				update tblRizeBargashtAzForoosh set  fldCodeTafsili=@NewCode where fldCodeTafsili=@OldCode
				update tblRizeBargashtAzKharid set  fldCodeVasete=@NewCode where fldCodeVasete=@OldCode
				update tblRizeBargashtAzKharid set  fldCodeTafsili=@NewCode where fldCodeTafsili=@OldCode
				update tblRizeForoosh set  fldCodeVasete=@NewCode where fldCodeVasete=@OldCode
				update tblRizeForoosh set  fldCodeTafsili=@NewCode where fldCodeTafsili=@OldCode
				update tblRizeForoosh set  fldCodeVasete2=@NewCode where fldCodeVasete2=@OldCode
				update tblRizeKharid set  fldCodeVasete=@NewCode where fldCodeVasete=@OldCode
				update tblRizeKharid set  fldCodeTafsili=@NewCode where fldCodeTafsili=@OldCode
				update tblRizePishForoosh set  fldCodeVasete=@NewCode where fldCodeVasete=@OldCode
				update tblRizePishForoosh set  fldCodeTafsili=@NewCode where fldCodeTafsili=@OldCode
				update tblRizePishPishForoosh set  fldCodeVasete=@NewCode where fldCodeVasete=@OldCode
				update tblRizePishPishForoosh set  fldCodeTafsili=@NewCode where fldCodeTafsili=@OldCode
				update tblRizHavaleHazine set  fldCodeVasete=@NewCode where fldCodeVasete=@OldCode
				update tblRizHavaleHazine set  fldCodeTafsili=@NewCode where fldCodeTafsili=@OldCode
				update tblSabteEtelaateSabeteHoghooghi set  fldCodePersonel=@NewCode where fldCodePersonel=@OldCode
				update tblSabteEtelaateSayereBimeha set  fldCodePersonel=@NewCode where fldCodePersonel=@OldCode
				update tblSabteVamhaVaSayereKosoor set  fldCodePersonel=@NewCode where fldCodePersonel=@OldCode
				update tblSodooreSanad set  fldCodeTafzili=@NewCode where fldCodeTafzili=@OldCode
				--update tblTafzili set  fldCodeTafzili=@NewCode where fldCodeTafzili=@OldCode
				update tblTafzili set  fldVisitor=@NewCode where fldVisitor=@OldCode
				update tblTafzili set  fldCodeSuperVisor=@NewCode where fldCodeSuperVisor=@OldCode
				update tblTasfie set  fldCodeTafzili=@NewCode where fldCodeTafzili=@OldCode
				update tblVamInfo set  fldCodeTafzili=@NewCode where fldCodeTafzili=@OldCode

			set @NoeKhata='changed'
	commit transaction
			end try

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

		end catch
end
GO

-- ===============================================
-- SP: [dbo].[ChapSanad2]
-- ===============================================
IF OBJECT_ID(N'dbo.ChapSanad2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ChapSanad2] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ChapSanad2]
@Shomaresanad nvarchar(50)

as
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END

	create  table #Sanad
		(
		[fldCodeKol] [nvarchar](50) COLLATE Persian_100_CI_AS NULL,
		[SharheKol]  [nvarchar](50) COLLATE Persian_100_CI_AS NULL,
		[fldCodeMoin] [nvarchar](10) COLLATE Persian_100_CI_AS NULL,
		[SharheMoin]  [nvarchar](50) COLLATE Persian_100_CI_AS NULL,
		[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS NOT NULL,
		[SharheTafzili]  [nvarchar](200) COLLATE Persian_100_CI_AS NULL,
		[fldCodeMarkaz1] [nvarchar](50) COLLATE Persian_100_CI_AS NULL,
		[SharheMarkaz1] [nvarchar](50) COLLATE Persian_100_CI_AS NULL,
		[fldCodeMarkaz2] [nvarchar](50) COLLATE Persian_100_CI_AS NULL,
		[SharheMarkaz2] [nvarchar](50) COLLATE Persian_100_CI_AS NULL,
		[fldBedehkar] [decimal](18, 2) NULL,
		[fldBestankar] [decimal](18, 2) NULL,
		[fldSharh] [nvarchar](150) NULL,
		[fldDate] [int] NULL,
		[fldCodeNoeTafzili] [nvarchar](50) COLLATE Persian_100_CI_AS NULL,
		)

begin
	
	insert into #Sanad
		([fldCodeKol],[fldCodeMoin] ,[fldCodeTafzili],[fldCodeMarkaz1],[fldCodeMarkaz2],[fldBedehkar],[fldBestankar],[fldSharh],fldDate,[fldCodeNoeTafzili] )
		Select [fldCodeKol],[fldCodeMoin] ,[fldCodeTafzili],[fldCodeMarkaz1],[fldCodeMarkaz2],[fldBedehkar],[fldBestankar],[fldSharh],fldDate,[fldCodeNoeTafzili]  from tblSodooreSanad Where fldSanad=23855

	update #sanad set SharheTafzili=tblTafzili.fldSharheTafzili from tblTafzili Where #Sanad.fldCodeTafzili=tblTafzili.fldCodeTafzili --And #Sanad.fldCodeNoeTafzili=tblTafzili.fldCodeNoe
	update #sanad set SharheKol=tblKolMoin.fldSharheHesab from tblKolMoin Where #Sanad.fldCodeKol=tblKolMoin.fldCodeHesab
	update #sanad set SharheMoin=tblKolMoin.fldSharheHesab from tblKolMoin Where #Sanad.fldCodeKol+ #Sanad.fldCodeMoin =tblKolMoin.fldCodeHesab
	update #sanad set SharheMarkaz1=tblMarkaz1.fldSharh from tblMarkaz1 Where #Sanad.fldCodeMarkaz1=tblMarkaz1.fldSharh
	update #sanad set SharheMarkaz1=tblMarkaz2.fldSharh from tblMarkaz2 Where #Sanad.fldCodeMarkaz2=tblMarkaz2.fldSharh

	Select  [fldCodeKol],[SharheKol],[fldCodeMoin],[SharheMoin],[fldCodeTafzili],[SharheTafzili],[fldCodeMarkaz1],[SharheMarkaz1],[fldCodeMarkaz2],[SharheMarkaz2],[fldBedehkar],[fldBestankar],[fldSharh],[fldDate],[fldCodeNoeTafzili] from #Sanad
	--select * from #Sanad

end
GO

-- ===============================================
-- SP: [dbo].[ChartAmalkardForooshVizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.ChartAmalkardForooshVizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ChartAmalkardForooshVizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ChartAmalkardForooshVizitor]
	@year bigint,
	@codevizitor nvarchar(10)

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;

	declare @strCodeMoinForoosh nvarchar(20),@JameForoosh bigint
    create table #tmpChartForoosh
		(
			fldNameMah nvarchar(20) COLLATE Persian_100_CI_AS,
			fldShomareMah bigint,
			fldJameForoosh bigint
		)
	
	
	execute CodeMoinHesab 'foroosh',@strCodeMoinForoosh output --'71301'
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldVasete=@codevizitor and fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0101' ) and Convert(bigint,  Convert(varchar, @year) + '0131' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
		
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('فروردین',1,@JameForoosh)
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where  fldVasete=@codevizitor and fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0201' ) and Convert(bigint,  Convert(varchar, @year) + '0231' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
		
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('اردیبهشت',2,@JameForoosh)
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldVasete=@codevizitor and  fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0301' ) and Convert(bigint,  Convert(varchar, @year) + '0331' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('خرداد',3,@JameForoosh)
	
	
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldVasete=@codevizitor and  fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0401' ) and Convert(bigint,  Convert(varchar, @year) + '0431' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('تیر',4,@JameForoosh)
	
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldVasete=@codevizitor and  fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0501' ) and Convert(bigint,  Convert(varchar, @year) + '0531' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('مرداد',5,@JameForoosh)
		
	
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where  fldVasete=@codevizitor and fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0601' ) and Convert(bigint,  Convert(varchar, @year) + '0631' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('شهریور',6,@JameForoosh)
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldVasete=@codevizitor and  fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0701' ) and Convert(bigint,  Convert(varchar, @year) + '0731' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('مهر',7,@JameForoosh)
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldVasete=@codevizitor and  fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0801' ) and Convert(bigint,  Convert(varchar, @year) + '0831' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('آبان',8,@JameForoosh)
		
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldVasete=@codevizitor and  fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0901' ) and Convert(bigint,  Convert(varchar, @year) + '0931' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('آذر',9,@JameForoosh)
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldVasete=@codevizitor and  fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '1001' ) and Convert(bigint,  Convert(varchar, @year) + '1031' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('دی',10,@JameForoosh)
		
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldVasete=@codevizitor and  fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '1101' ) and Convert(bigint,  Convert(varchar, @year) + '1131' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('بهمن',11,@JameForoosh)	
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldVasete=@codevizitor and  fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '1201' ) and Convert(bigint,  Convert(varchar, @year) + '1231' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('اسفند',12,@JameForoosh)
		
	select fldNameMah,fldShomareMah,fldJameForoosh from #tmpChartForoosh		
END
GO

-- ===============================================
-- SP: [dbo].[chartForooshMahaneVizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.chartForooshMahaneVizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[chartForooshMahaneVizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[chartForooshMahaneVizitor]
@Sal int,
@DateAz int,
@dateTa int,
@codeVizitor nvarchar(10)
as 

begin

	SELECT        SUM(fldMablaghKhales) AS Sum1, fldDate
		FROM            tblRizeForoosh
		WHERE        (fldCodeVasete = @codeVizitor) AND (fldDate BETWEEN @DateAz AND @dateTa)
		GROUP BY fldDate
		order by flddate
end
GO

-- ===============================================
-- SP: [dbo].[ChartvarizMahane]
-- ===============================================
IF OBJECT_ID(N'dbo.ChartvarizMahane', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ChartvarizMahane] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ChartvarizMahane]
	@noenteghal int,
	@year bigint
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;

	declare @strCodeBank nvarchar(20),@strCodeSandoogh nvarchar(20),@JameForoosh bigint
    create table #tmpChartForoosh
		(
			fldNameMah nvarchar(20) COLLATE Persian_100_CI_AS,
			fldShomareMah bigint,
			fldJameForoosh bigint
		)
	
	
	execute CodeKolHesab 'bank',@strCodeBank output --'71301'
	execute CodeKolHesab 'sandoogh',@strCodeSandoogh output

	if @noenteghal=1 
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0101' ) and Convert(bigint,  Convert(varchar, @year) + '0131' ) and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0101' ) and Convert(bigint,  Convert(varchar, @year) + '0131' ))  

	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
		
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('فروردین',1,@JameForoosh)
	
	if @noenteghal=1 	
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0201' ) and Convert(bigint,  Convert(varchar, @year) + '0231' ) and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0201' ) and Convert(bigint,  Convert(varchar, @year) + '0231' ) )

	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
		
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('اردیبهشت',2,@JameForoosh)
		
	if @noenteghal=1 
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0301' ) and Convert(bigint,  Convert(varchar, @year) + '0331' ) and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0301' ) and Convert(bigint,  Convert(varchar, @year) + '0331' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('خرداد',3,@JameForoosh)
	
	if @noenteghal=1 
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0401' ) and Convert(bigint,  Convert(varchar, @year) + '0431' ) and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0401' ) and Convert(bigint,  Convert(varchar, @year) + '0431' ))

	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('تیر',4,@JameForoosh)
	
	if @noenteghal=1 
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0501' ) and Convert(bigint,  Convert(varchar, @year) + '0531' ) and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0501' ) and Convert(bigint,  Convert(varchar, @year) + '0531' ))

	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('مرداد',5,@JameForoosh)
		
	if @noenteghal=1 
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0601' ) and Convert(bigint,  Convert(varchar, @year) + '0631' ) and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0601' ) and Convert(bigint,  Convert(varchar, @year) + '0631' ))

	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('شهریور',6,@JameForoosh)
		
	if @noenteghal=1 	
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0701' ) and Convert(bigint,  Convert(varchar, @year) + '0731' ) and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0701' ) and Convert(bigint,  Convert(varchar, @year) + '0731' ))

	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('مهر',7,@JameForoosh)
		
	if @noenteghal=1 
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0801' ) and Convert(bigint,  Convert(varchar, @year) + '0831' ) and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0801' ) and Convert(bigint,  Convert(varchar, @year) + '0831' ))

	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('آبان',8,@JameForoosh)
		
		
	if @noenteghal=1 
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0901' ) and Convert(bigint,  Convert(varchar, @year) + '0931' )and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '0901' ) and Convert(bigint,  Convert(varchar, @year) + '0931' ))

	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('آذر',9,@JameForoosh)
		
	if @noenteghal=1
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '1001' ) and Convert(bigint,  Convert(varchar, @year) + '1031' ) and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '1001' ) and Convert(bigint,  Convert(varchar, @year) + '1031' ))

	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('دی',10,@JameForoosh)
		
		
	if @noenteghal=1
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '1101' ) and Convert(bigint,  Convert(varchar, @year) + '1131' ) and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '1101' ) and Convert(bigint,  Convert(varchar, @year) + '1131' ))


	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('بهمن',11,@JameForoosh)	
		
	if @noenteghal=1
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '1201' ) and Convert(bigint,  Convert(varchar, @year) + '1231' )and fldtype<>'enteghalevajh')
	else
		set @JameForoosh=(Select  SUM(fldBedehkar-fldBestankar) As SumForoosh from tblSodooreSanad	Where (fldCodeKol=@strCodeBank or fldCodeKol=@strCodeSandoogh) And flddate between Convert(bigint, Convert(varchar, @year) + '1201' ) and Convert(bigint,  Convert(varchar, @year) + '1231' ))

	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('اسفند',12,@JameForoosh)
		
	select fldNameMah,fldShomareMah,fldJameForoosh from #tmpChartForoosh		
END
GO

-- ===============================================
-- SP: [dbo].[Check_AmalKard_IDGroupAshkhas_TblAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.Check_AmalKard_IDGroupAshkhas_TblAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Check_AmalKard_IDGroupAshkhas_TblAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[Check_AmalKard_IDGroupKalaIN_TblKala]
-- ===============================================
IF OBJECT_ID(N'dbo.Check_AmalKard_IDGroupKalaIN_TblKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Check_AmalKard_IDGroupKalaIN_TblKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[Check_AmlKard_CodeTafzili_For_Delete_In_Tbl_Tafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.Check_AmlKard_CodeTafzili_For_Delete_In_Tbl_Tafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Check_AmlKard_CodeTafzili_For_Delete_In_Tbl_Tafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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
else
	begin
		set @hasrowinSanad=(select count(fldCodeTafsili) from tblRizePishForoosh  where fldCodeTafsili=@fldCodeTafzili)
		if (@hasrowinSanad > 0)
			begin
				set @flagDelete_Tafzili=1
				return
			end
		else
			begin
				set @hasrowinSanad=(select count(fldCodeTafsili) from tblRizePishPishForoosh  where fldCodeTafsili=@fldCodeTafzili)
				if (@hasrowinSanad > 0)
					begin
						set @flagDelete_Tafzili=1
						return
					end
			end

	end
end
GO

-- ===============================================
-- SP: [dbo].[Check_CodeTafzili_Delete_Tbl_Tafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.Check_CodeTafzili_Delete_Tbl_Tafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Check_CodeTafzili_Delete_Tbl_Tafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[checkIdNumber_GruopAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.checkIdNumber_GruopAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[checkIdNumber_GruopAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[checkIdNumber_GruopKala]
-- ===============================================
IF OBJECT_ID(N'dbo.checkIdNumber_GruopKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[checkIdNumber_GruopKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[CodeKolHesab]
-- ===============================================
IF OBJECT_ID(N'dbo.CodeKolHesab', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[CodeKolHesab] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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	
	else if @NameHesab='tarafeentezami'
		begin
			set @Meghdar=(Select  fldkolTarafEntezami from tblTanzimat )		
		end 

end
GO

-- ===============================================
-- SP: [dbo].[CodeMoinHesab]
-- ===============================================
IF OBJECT_ID(N'dbo.CodeMoinHesab', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[CodeMoinHesab] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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='checkvagozaripersonel' 
		begin
			set @Meghdar=(Select  fldMoinCheckVagozariPersonel 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 
	else if @NameHesab='forooshamani'
		begin
			set @Meghdar=(Select  fldMoinAmani from tblTanzimat )
		end		
	else if @NameHesab='checkpersonel'
		begin
			set @Meghdar=(Select  fldMoinCheckPersonel from tblTanzimat )
		end 
	else if @NameHesab='karmozdevam'
		begin
			set @Meghdar=(Select  fldMoinKarmozdeVam from tblTanzimat )
		end 
	else if @NameHesab='hoghooghesabet'
		begin
			set @Meghdar=(Select  fldMoinHoghoogh from tblTanzimat )
		end 	
	else if @NameHesab='karmozd'
		begin
			set @Meghdar=(Select top(1)fldMeghdar from tblTanzimateKol where  fldType='moinkamelkarmozd'  )
		end 
end
GO

-- ===============================================
-- SP: [dbo].[codenoetafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.codenoetafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[codenoetafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[codenoetafzili]

as

begin
	select  fldName, fldCode from tblTafziliType

end
GO

-- ===============================================
-- SP: [dbo].[daftereelectronici]
-- ===============================================
IF OBJECT_ID(N'dbo.daftereelectronici', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[daftereelectronici] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[daftereelectronici]

@datefrom int,
@dateTa int,
@Type nvarchar(15)
as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin

	create table #tbl1(
		fldCodeKol nvarchar(10) COLLATE Persian_100_CI_AS,
		fldSharheKol nvarchar(50) COLLATE Persian_100_CI_AS,
		fldCodeMoin nvarchar(10) COLLATE Persian_100_CI_AS,
		fldSharheMoin nvarchar(50) COLLATE Persian_100_CI_AS,
		fldCodetafzili nvarchar(10) COLLATE Persian_100_CI_AS,
		fldSharheTafzili nvarchar(200) COLLATE Persian_100_CI_AS,
		fldBedehkar bigint,
		fldBestankar bigint,
		fldDate  nvarchar(15) COLLATE Persian_100_CI_AS,
		fldDateShow nvarchar(15),
		fldsanad nvarchar(15),
		fldRadif nvarchar(3) COLLATE Persian_100_CI_AS
	)

	--insert into #tbl1(fldCodeKol,fldCodeMoin ,fldCodetafzili,fldBedehkar,fldDate)
	--	(select fldCodeKol,fldCodeMoin ,fldCodetafzili,fldBedehkar-fldBestankar,fldDate from tblSodooreSanad where flddate between @datefrom and @dateTa)
	if @Type='mahane'
		begin
			declare @year nvarchar(4)
			set  @year=substring(convert(varchar,@datefrom),1,4)

			insert into #tbl1(fldCodeKol,fldCodeMoin ,fldBedehkar,fldDate,fldsanad,fldRadif)
				(select fldCodeKol,fldCodeMoin ,sum(fldBedehkar),(@year + fldMonth + 'xx') as flddate,'0','0' from tblSodooreSanad where fldDate between @datefrom and @dateTa  group by fldCodeKol,fldCodeMoin,fldMonth)

			insert into #tbl1(fldCodeKol,fldCodeMoin ,fldBestankar,fldDate,fldsanad,fldRadif)
				(select fldCodeKol,fldCodeMoin ,sum(fldBestankar),(@year + fldMonth + 'xx') as flddate,'0','1' from tblSodooreSanad where fldDate between @datefrom and @dateTa  group by fldCodeKol,fldCodeMoin,fldMonth)
			update #tbl1 set fldDate=REPLACE(flddate,'xx','31')  where convert(int, SUBSTRING( convert(varchar,fldDate),5,2)) between 1 and 6
			update #tbl1 set fldDate=REPLACE(flddate,'xx','30')  where convert(int, SUBSTRING( convert(varchar,fldDate),5,2)) between 7 and 11
			update #tbl1 set fldDate=REPLACE(flddate,'xx','29')  where convert(int, SUBSTRING( convert(varchar,fldDate),5,2))=12
		end
	if @Type='tajmi'
		insert into #tbl1(fldCodeKol,fldCodeMoin ,fldBedehkar,fldDate,fldsanad,fldRadif)
			(select fldCodeKol,fldCodeMoin ,sum(fldBedehkar-fldBestankar),fldDate,'0','0' from tblSodooreSanad where fldDate between @datefrom and @dateTa  group by fldCodeKol,fldCodeMoin,fldDate,fldSanad)
	if @type='tafkik'		
		begin
			insert into #tbl1(fldCodeKol,fldCodeMoin ,fldBedehkar,fldBestankar,fldDate,fldsanad,fldRadif)
				(select fldCodeKol,fldCodeMoin ,fldBedehkar,fldBestankar,fldDate,fldsanad,fldRadif from tblSodooreSanad where fldDate between @datefrom and @dateTa   )
		
			update #tbl1 set fldBedehkar=fldBedehkar-fldBestankar
			update #tbl1 set fldBestankar=0
		end

	if @Type<>'mahane'
		begin
			update #tbl1 set fldbestankar=-1*fldbedehkar,fldBedehkar=0 where fldBedehkar<0
		end
	
	update #tbl1 set fldbestankar=0 where fldbestankar is NULL
	update #tbl1 set fldbedehkar=0 where fldbedehkar is NULL
	update #tbl1 set fldSharheKol=tblKolMoin.fldSharheHesab from tblKolMoin where tblKolMoin.fldCodeHesab=#tbl1.fldCodeKol
	update #tbl1 set fldSharheMoin=tblKolMoin.fldSharheHesab from tblKolMoin where tblKolMoin.fldCodeHesab=(#tbl1.fldCodeKol+#tbl1.fldCodeMoin)
	--update #tbl1 set fldSharheTafzili=tblTafzili.fldSharheTafzili from tblTafzili where tblTafzili.fldCodeTafzili=#tbl1.fldCodetafzili
	update #tbl1 set fldDateShow=substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2)


	select '' as fldRadif,fldDateShow as fldDate, fldCodeKol,fldSharheKol,fldCodeMoin ,fldSharheMoin,'' as fldSharh,fldBedehkar,fldbestankar ,fldsanad  from #tbl1 where not( fldBedehkar=0 and fldBestankar=0) order by fldDate,convert(bigint,fldsanad),fldCodeKol,fldCodeMoin,fldBestankar

	--select * from tblSodooreSanad where fldMoinKamel='10902' and fldDate between 14040104 and 14040115
	--select sum(fldBedehkar-fldBestankar) from tblSodooreSanad where fldMoinKamel='10902' and fldDate between 14040104 and 14040115
end
GO

-- ===============================================
-- SP: [dbo].[Dashbord]
-- ===============================================
IF OBJECT_ID(N'dbo.Dashbord', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Dashbord] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Dashbord]

@TblVasete [tbl1] readonly,
@dateAz bigint,
@dateTa bigint,

@SumForoosh decimal(18,2) output,
@SumForooshTakhfifGhalam decimal(18,2) output,
@ForooshArzesheAfzoode decimal(18,2) output,
@SumForooshKhales decimal(18,2) output,

@SumBargasht decimal(18,2) output,
@SumBargashtTakhfif decimal(18,2) output,
@SumBargashtArzesheAfzoode decimal(18,2) output,
@SumBargashtKhales decimal(18,2) output,

@SumDaryaftNaghd decimal(18,2) output,
@SumDaryaftBank decimal(18,2) output,
@SumDaryaftCheck decimal(18,2) output,
@SumDaryaftTakhfif decimal(18,2) output,
@SumdaryaftKhales decimal(18,2) output,

@SumPardakhtNaghd decimal(18,2) output,
@SumPardakhtBank decimal(18,2) output,
@SumPardakhtCheck decimal(18,2) output,
@SumPardakhtTakhfif decimal(18,2) output,
@SumPardakhtKhales decimal(18,2) output,
@SumPardakhtCheckForoosh decimal(18,2) output
as 

begin
	declare @CodeKolSandoogh  nvarchar(5),@CodeKolBank nvarchar(5),@CodeMoinTakhfifDaryaft nvarchar(5),@CodeMoinTakhfifPardakht nvarchar(5),@CodeMoinCheckDaryafti nvarchar(5)

	execute CodeKolHesab 'sandoogh',@CodeKolSandoogh output
	execute CodeKolHesab 'bank',@CodeKolBank output
	execute CodeMoinHesab 'takhfifatedaryaft',@CodeMoinTakhfifDaryaft output
	execute CodeMoinHesab 'takhfifatepardakht',@CodeMoinTakhfifPardakht output
	execute CodeMoinHesab 'check',@CodeMoinCheckDaryafti output	
	

	set @SumForoosh=(select Sum(fldFeeKol) as SumFee from tblRizeForoosh Where flddate between @dateAz and @dateTa and  fldCodeVasete in (select fld1 from  @TblVasete))
	set @SumForooshTakhfifGhalam=(select Sum(fldMablaghTakhfif) as SumTakhfif from tblRizeForoosh Where flddate between @dateAz and @dateTa and fldCodeVasete in (select fld1 from  @TblVasete))
	set @ForooshArzesheAfzoode=(select Sum(fldArzeshAfzode) as SumTakhfif from tblRizeForoosh Where flddate between @dateAz and @dateTa and fldCodeVasete in (select fld1 from  @TblVasete))
	set @SumForooshKhales=(select Sum(fldMablaghKhales) as SumTakhfif from tblRizeForoosh Where  flddate between @dateAz and @dateTa and fldCodeVasete in (select fld1 from  @TblVasete))
	
	set @SumBargasht=(select Sum(fldFeeKol) as SumFee from tblRizeBargashtAzForoosh Where flddate between @dateAz and @dateTa and fldCodeVasete in (select fld1 from  @TblVasete))
	set @SumBargashtTakhfif=(select Sum(fldMablaghTakhfif) as SumTakhfif from tblRizeBargashtAzForoosh Where flddate between @dateAz and @dateTa and fldCodeVasete in (select fld1 from  @TblVasete))
	set @SumBargashtArzesheAfzoode=(select Sum(fldArzeshAfzode) as SumTakhfif from tblRizeBargashtAzForoosh Where flddate between @dateAz and @dateTa and fldCodeVasete in (select fld1 from  @TblVasete))
	set @SumBargashtKhales=(select Sum(fldMablaghKhales) as SumTakhfif from tblRizeBargashtAzForoosh Where flddate between @dateAz and @dateTa and fldCodeVasete in (select fld1 from  @TblVasete))


	set @SumDaryaftNaghd=(select Sum(fldBedehkar) as SumFee from tblsodooresanad Where flddate between @dateAz and @dateTa and  fldcodekol=@CodeKolSandoogh and fldVasete in (select fld1 from  @TblVasete))
	set @SumDaryaftBank =(select Sum(fldBedehkar) as SumFee from tblsodooresanad Where flddate between @dateAz and @dateTa and  fldcodekol=@CodeKolBank and fldVasete in (select fld1 from  @TblVasete))
	set @SumDaryaftTakhfif=(select Sum(fldBedehkar) as SumFee from tblsodooresanad Where flddate between @dateAz and @dateTa and  fldMoinKamel=@CodeMoinTakhfifDaryaft and fldVasete in (select fld1 from  @TblVasete))
	set @SumDaryaftCheck=(select Sum(fldMablagh) as SumFee from tblCheckeDaryafti Where fldDateDaryaft between @dateAz and @dateTa and  fldVasete in (select fld1 from  @TblVasete))	

	if ISNUMERIC(@SumDaryaftNaghd)=0
		set @SumDaryaftNaghd=0
	if ISNUMERIC(@SumDaryaftBank)=0
		set @SumDaryaftBank=0
	if isnumeric( @SumDaryaftCheck)=0 
		set @SumDaryaftCheck=0
	if isnumeric(@SumDaryaftTakhfif)=0
		set @SumDaryaftTakhfif=0
	set @SumdaryaftKhales=(@SumDaryaftNaghd+@SumDaryaftBank+@SumDaryaftCheck-@SumDaryaftTakhfif)


	set @SumPardakhtNaghd =(select Sum(fldBestankar) as SumFee from tblsodooresanad Where flddate between @dateAz and @dateTa and  fldcodekol=@CodeKolSandoogh and fldVasete in (select fld1 from  @TblVasete))
	set @SumPardakhtBank =(select Sum(fldBestankar) as SumFee from tblsodooresanad Where flddate between @dateAz and @dateTa and  fldcodekol=@CodeKolBank and fldVasete in (select fld1 from  @TblVasete))
	set @SumPardakhtCheck =(select Sum(fldMablagh) as SumFee from tblCheckePardakhti Where fldDatePardakht between @dateAz and @dateTa and  fldVasete in (select fld1 from  @TblVasete))	
	set @SumPardakhtTakhfif=(select Sum(fldBestankar) as SumFee from tblsodooresanad Where flddate between @dateAz and @dateTa and  fldMoinKamel=@CodeMoinTakhfifPardakht and fldVasete in (select fld1 from  @TblVasete))
	set @SumPardakhtCheckForoosh=(select Sum(fldBestankar) as SumFee from tblsodooresanad Where flddate between @dateAz and @dateTa and  fldMoinKamel=@CodeMoinCheckDaryafti and fldVasete in (select fld1 from  @TblVasete))	

	if isnumeric(@SumPardakhtNaghd)=0
		set @SumPardakhtNaghd=0
	if isnumeric(@SumPardakhtBank)=0
		set @SumPardakhtBank=0
	if isnumeric(@SumPardakhtCheck)=0		
		set @SumPardakhtCheck=0
	if isnumeric(@SumPardakhtTakhfif)=0
		set @SumPardakhtTakhfif=0
	if isnumeric(@SumPardakhtCheckForoosh)=0
		set	@SumPardakhtCheckForoosh=0

	set @SumPardakhtKhales =(@SumPardakhtNaghd+@SumPardakhtBank+@SumPardakhtCheck+@SumPardakhtCheckForoosh-@SumPardakhtTakhfif)



end
GO

-- ===============================================
-- SP: [dbo].[dastrasipersonel]
-- ===============================================
IF OBJECT_ID(N'dbo.dastrasipersonel', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[dastrasipersonel] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[dastrasipersonel]
@CodeUser int

as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin

create table #tblTemp(
	fldCodeTafzili nvarchar(10)  COLLATE Persian_100_CI_AS NULL,
	fldSharhetafzili nvarchar(200)  COLLATE Persian_100_CI_AS NULL,
	fldCheck bit
)
	
insert #tblTemp 
	(fldcodetafzili,fldSharhetafzili,fldCheck)
	select fldCodeTafzili,fldSharheTafzili,0 from tblTafzili where fldCodeNoe='0'

	update #tblTemp set fldCheck=1 where fldCodeTafzili in (select fldCodeTafzili from tblDastrasiPersonel where fldcodeUser=@CodeUser)

select fldcodetafzili,fldSharhetafzili,fldCheck from #tblTemp





end
GO

-- ===============================================
-- SP: [dbo].[dastrasiUser]
-- ===============================================
IF OBJECT_ID(N'dbo.dastrasiUser', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[dastrasiUser] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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(40) 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

-- ===============================================
-- SP: [dbo].[DataMokhtalef]
-- ===============================================
IF OBJECT_ID(N'dbo.DataMokhtalef', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DataMokhtalef] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[Date6Raghami]
-- ===============================================
IF OBJECT_ID(N'dbo.Date6Raghami', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Date6Raghami] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Date6Raghami]

@DateKamel bigint,
@DateSmall bigint Output
as

begin	
	declare @strDateKamel varchar(10),@strDateSmall varchar(10)
	set @strDateKamel=convert(varchar,@DateKamel)

	set @strDateSmall=substring( @strDateKamel,3,6)
	set @DateSmall=CONVERT(bigint,@strDateSmall)
	--select @strDateSmall from tblsodooreSanad
end
GO

-- ===============================================
-- SP: [dbo].[Date9Raghami]
-- ===============================================
IF OBJECT_ID(N'dbo.Date9Raghami', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Date9Raghami] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Date9Raghami]

@DateSmall int,
@DateKamel int Output
as

begin	
	declare @strDateSmall varchar(10),@strDateKamel varchar(10)
	set @strDateSmall=convert(varchar,@DateSmall)


	declare @PishSal nvarchar(70)
	set @PishSal=(Select fldMeghdar from tblTanzimateKol Where fldType='pishsal')
	if isnumeric(@PishSal )=0
		set @PishSal=13

	if len(convert(nvarchar(20),@DateSmall))<8
		begin
			set @strDateKamel=@PishSal + @strDateSmall
			set @DateKamel=CONVERT(int,@strDateKamel)
		end 
	else
		set @DateKamel=@DateSmall

end
GO

-- ===============================================
-- SP: [dbo].[DateToShow]
-- ===============================================
IF OBJECT_ID(N'dbo.DateToShow', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DateToShow] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[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

-- ===============================================
-- SP: [dbo].[DateToShow6Va9Ragham]
-- ===============================================
IF OBJECT_ID(N'dbo.DateToShow6Va9Ragham', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DateToShow6Va9Ragham] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[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

-- ===============================================
-- SP: [dbo].[Delete_Tbl_DaftarcheTell]
-- ===============================================
IF OBJECT_ID(N'dbo.Delete_Tbl_DaftarcheTell', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Delete_Tbl_DaftarcheTell] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Delete_Tbl_DaftarcheTell]
@fldIdTell	bigint,
@flagDelete int output	
as
begin


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

-- ===============================================
-- SP: [dbo].[Delete_Tbl_Tafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.Delete_Tbl_Tafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Delete_Tbl_Tafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[DeleteAllInfo]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteAllInfo', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteAllInfo] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[DeleteAllInfo] 
	-- Add the parameters for the stored procedure here
	@Anbar int,
	@Kala int,
	@DaftarcheTell int,
	@Ashkhas int,	
	@BankeMoshtari int,
	@hoghoogh int,
	@FormooleTolid int
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	if @FormooleTolid=1 
		delete from tblRizeFormooleTolid
	if @hoghoogh=1 
		begin
			delete 	tblEidi
			delete tblErtebateKoding
			delete tblGharardad
			delete tblGhestevam
			delete tblInformation
			delete tblJadvaleMaliati
			delete tblKarkardeMahane
			delete tblMazayayeSabeteHoghooghi
			delete tblMoarefieBankha
			delete tblMoarefieKargah
			delete tblMoarefiePersonel
			delete tblMoshakhasatePardakhtKonande
			delete tblSabteEtelaateSabeteHoghooghi
			delete tblSabteEtelaateSayereBimeha
			delete tblSabteVamhaVaSayereKosoor
			delete tblSanavat
			delete tblSarfasleVam
			delete tblSayereBimeha
			delete tblZarayebeSabeteHoghooghi		
			return 
		end


    -- 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 tblPishForoosh
	delete from tblRizHavaleHazine
	delete from tblRizePishForoosh
	delete from tblVosool
	delete from tblDasteCheck
	delete from tblTasfie	
	delete from tblRizeTasfie
	delete from tblRizeTolid	
	delete from tblHavaleGoroohi
	delete from tblRizeForooshFastFood		
	delete from tblPishPishForoosh	
	delete from tblEtesalRanandeBeAnbar
	delete from tblSmsRizeSms
	delete from tblVamInfo
	delete from tblMadarekeVam
	delete from tblRizeTasfieVam
	delete from tblDaftarcheAghsat
	delete from tblTarheTakhfifHajmiGroupKala
	delete    tblAnbarAmani
	delete tblanbar where fldCode>=2000
	delete tblRizeChangeInFactor
	delete      tblBaskool
	delete tblMoadianArchive
	delete tblMoghayratMojoodieAnbar
	delete tblSmsFromServer
	--delete tblTafziliType
	delete tblTarheTakhfifeRadifi
	delete tblTtacPendingBargashtAzForoosh
	delete tblTtacPendingBargashtAzForooshAmani
	delete tblTtacPendingBargashtAzKharid
	delete tblTtacPendingEnteghalKalaAnbar
	delete tblTtacPendingForoosh
	delete tblTtacPendingForooshAmani
	delete tblTtacPendingHavaleGroup
	delete tblTtacPendingKharid
	delete tblTtacPendingMojodiEbteda
	delete tblTtacPendingTolid



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

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

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

	if @Ashkhas=1
		begin
			delete from tblTafzili Where fldCodeTafzili<>10000 and fldCodeTafzili<>10001
			delete from tblGroupAshkhas Where fldGroupId<>100 and fldGroupId<>101
			delete from tblListPorsantVaset
			delete from  tblPorsantVisitor

			if @DaftarcheTell=1 
				Delete  tblDaftarcheTell 
			else
				update tblDaftarcheTell set fldCodeTafzili=0
		end

	if @BankeMoshtari=1
		delete from tblBankeMoshtari


	declare @cnt bigint

	set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='deleteall' )
	
	if @cnt is null
		set @cnt=1
	else
		set @cnt+=1


	delete from tblDeleteList
	delete from tblAmalkardekarbar

	delete from tbleshantionmablagy
	delete from tblTarheTakhfif
	delete from tblTarheTakhfifHajmi
	delete from tblTarheTakhfifNaghdi
	delete from tblTimeOfSms
	DELETE FROM tblSharheFactorTasfie

	insert into tblDeleteList(id,fldCode,fldtype)
				values(@cnt,0,'deleteall')

END
GO

-- ===============================================
-- SP: [dbo].[DeleteChapgar]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteChapgar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteChapgar] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[DeleteDaryaft]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteDaryaft', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteDaryaft] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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	
			delete from tblRizeTasfieVam Where fldShomareDaryaft=@ShomareDaryaft	

			set @NoeKhata='deleteok'
	commit transaction
			end try

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

		end catch
end
GO

-- ===============================================
-- SP: [dbo].[DeleteDasteCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteDasteCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteDasteCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[DeleteDasteCheck]
@Serial bigint,
@CodeBank bigint
as

begin
	Delete from tblDasteCheck Where fldShomareCheck=@serial and fldCodeBank=@CodeBank
end
GO

-- ===============================================
-- SP: [dbo].[DeleteFactorAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteFactorAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteFactorAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[DeleteFactorAmani]
   @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 tblRizeKharid
						where fldShomareSanad=@fldShomareSanad --and fldShomareFactor=@fldShomareFactor
							IF @@ROWCOUNT = 0  
								begin
										set @strResult='NotDeletedRizeForoosh'
										rollback transaction DelRecord;
								end
					delete from tblSodooreSanad
						where fldSanad=@fldShomareSanad
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedtblSodooreSanad'
										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

-- ===============================================
-- SP: [dbo].[DeleteFactorBargashtAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteFactorBargashtAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteFactorBargashtAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[DeleteFactorBargashtAmani]
   @fldShomareSanad bigint,
   @fldShomareFactor bigint,
   @strResult nvarchar(25) output
AS
BEGIN
	
	SET NOCOUNT ON;
	begin transaction DelRecord
		begin try
	--delete
					delete from tblRizeBargashtAzForoosh
						where fldShomareSanad=@fldShomareSanad --and fldShomareFactor=@fldShomareFactor
							IF @@ROWCOUNT = 0  
								begin
										set @strResult='NotDeletedRizeForoosh'
										rollback transaction DelRecord;
								end
					delete from tblRizeKharid
						where fldShomareSanad=@fldShomareSanad --and fldShomareFactor=@fldShomareFactor
							IF @@ROWCOUNT = 0  
								begin
										set @strResult='NotDeletedRizeForoosh'
										rollback transaction DelRecord;
								end
					delete from tblSodooreSanad
						where fldSanad=@fldShomareSanad
								IF @@ROWCOUNT = 0  
									begin
										set @strResult='NotDeletedtblSodooreSanad'
										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

-- ===============================================
-- SP: [dbo].[DeleteFactorbARGASHTaZForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteFactorbARGASHTaZForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteFactorbARGASHTaZForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[DeleteFactorbargashtazkharid]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteFactorbargashtazkharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteFactorbargashtazkharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

--کامل نیست  (واگذاری چک تعیین نشده)
Alter 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

-- ===============================================
-- SP: [dbo].[DeleteFactorForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteFactorForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteFactorForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[DeleteFactorKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteFactorKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteFactorKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

--کامل نیست  (واگذاری چک تعیین نشده)
Alter 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

-- ===============================================
-- SP: [dbo].[DeleteFactorPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteFactorPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteFactorPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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		
					update tblForoosh set fldShomarePishFactor=NULL Where fldShomarePishFactor=@fldShomareFactor													
					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

-- ===============================================
-- SP: [dbo].[DeleteFactorPishPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteFactorPishPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteFactorPishPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[DeleteFactorPishPishForoosh]   
   @fldShomareFactor bigint,
   @strResult nvarchar(25) output
AS
BEGIN
	
	SET NOCOUNT ON;
	begin transaction DelRecord
		begin try

		
		--select * from tblforoosh
	--delete
					delete from tblRizePishPishForoosh
						where  fldShomareFactor=@fldShomareFactor

						update tblforoosh set  fldShomarePishFactor=NULL Where fldShomarePishFactor  = @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

-- ===============================================
-- SP: [dbo].[DeleteFullKala]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteFullKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteFullKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

			delete tblImageKala Where fldCodeKala = @IdKalaForoosh

			delete tblMultiFeeDynamic where fldCodeKala = @IdKalaForoosh

			delete from tblKala
				where fldCodeKala=@IdKalaForoosh

			set @fldResult=1
	commit transaction
		end try

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

	end catch


END
GO

-- ===============================================
-- SP: [dbo].[DeleteGroupAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteGroupAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteGroupAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[DeleteGroupKala]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteGroupKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteGroupKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[DeleteInfo_Ebteda_Doreh_Ashkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteInfo_Ebteda_Doreh_Ashkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteInfo_Ebteda_Doreh_Ashkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[DeleteInfo_MojodiEbteda_Doreh]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteInfo_MojodiEbteda_Doreh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteInfo_MojodiEbteda_Doreh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

	Delete from tblSodooreSanad where fldSanad=@fldShomareSanad And fldType='mojoodieebteda'
	Delete from tblRizeKharid where fldShomareSanad=@fldShomareSanad And fldType='mojodi_ebteda_doreh'
	
END
GO

-- ===============================================
-- SP: [dbo].[DeleteInfoEnteghal]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteInfoEnteghal', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteInfoEnteghal] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[DeleteInfoKhabanidanCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteInfoKhabanidanCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteInfoKhabanidanCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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,
	 fldDateBargasht=NULL
    
 WHERE ID=@fldIdCheck 
    set @Result='DeleteOK'
	
END

SET ANSI_NULLS ON
GO

-- ===============================================
-- SP: [dbo].[DeleteInfoVosoolCheck_Final]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteInfoVosoolCheck_Final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteInfoVosoolCheck_Final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[DeleteInfoVosoolCheck_Final] 
@fldShomareVosool bigint,
@strResult nvarchar(25) output
as            
BEGIN
	begin transaction transact
	begin try
	
		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
				----///
	commit transaction
	end try

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

	end catch
END
GO

-- ===============================================
-- SP: [dbo].[DeleteMahHoghoogh]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteMahHoghoogh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteMahHoghoogh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[DeleteMahHoghoogh]

@Mah nvarchar(2)
as 

begin

declare @NewMah nvarchar(2)

delete  tblForReport where fldmah=@mah

delete         tblJadvaleMaliati where fldmah=@mah

delete     tblKarkardeMahane where fldmah=@mah

delete      tblMazayayeSabeteHoghooghi where fldmah=@mah

delete tblMoarefieKargah where fldmah=@mah

delete   tblMoarefiePersonel where fldmah=@mah

delete   tblSarfasleVam where fldmah=@mah

delete         tblSabteVamhaVaSayereKosoor where fldmah=@mah

delete      tblSabteEtelaateSabeteHoghooghi where fldmah=@mah

delete   tblSabteEtelaateSayereBimeha where fldmah=@mah

delete    tblSayereBimeha where fldmah=@mah

delete  tblZarayebeSabeteHoghooghi where fldmah=@mah

delete tblPayeSanavat where fldmah=@mah

if @Mah=1
	set @NewMah='1'
else
	set @NewMah=@Mah-1

update tblControlPanel set fldLastMah=@NewMah
update tblControlPanel set  fldMaheDarhaleEjra=@NewMah

end
GO

-- ===============================================
-- SP: [dbo].[DeletePardakht]
-- ===============================================
IF OBJECT_ID(N'dbo.DeletePardakht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeletePardakht] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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 ,fldVaziat=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

-- ===============================================
-- SP: [dbo].[DeletePaseCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.DeletePaseCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeletePaseCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[DeletePaseCheck] 
	-- Add the parameters for the stored procedure here
	@fldShomarePas bigint,
	@NoeKhata nvarchar(30) output 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	begin transaction transact
	begin try
		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
	commit transaction
	end try

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

	end catch
							
END
GO

-- ===============================================
-- SP: [dbo].[DeleteSandoogh]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteSandoogh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteSandoogh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[DeleteSandoogh]
@CodeSandoogh nvarchar(50)
as
begin
		declare @id int

	set	@id=(select ID from tblKolMoin where fldCodeHesab=@CodeSandoogh)

		
		execute DeleteTblKolMoin @id

end
GO

-- ===============================================
-- SP: [dbo].[DeleteSuperVizor]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteSuperVizor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteSuperVizor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[DeleteSuperVizor]
	-- Add the parameters for the stored procedure here
	@ID bigint
AS
BEGIN
	declare @CodeTafzili nvarchar(20)
	set @CodeTafzili=(Select fldcodeTafzili from tblTafzili where id=@id)

	Delete from tblTafzili Where ID=@Id
	update tblTafzili set fldVisitor=0 where fldVisitor=@CodeTafzili

END
GO

-- ===============================================
-- SP: [dbo].[DeleteTblAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteTblAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteTblAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc  [dbo].[DeleteTblAnbar]
@ID as int

as
begin
Delete from tblAnbar Where ID=@ID
end
GO

-- ===============================================
-- SP: [dbo].[DeleteTblBankeMoshtari]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteTblBankeMoshtari', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteTblBankeMoshtari] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc  [dbo].[DeleteTblBankeMoshtari]
@ID as int

as
begin
Delete from tblBankeMoshtari Where ID=@ID
end
GO

-- ===============================================
-- SP: [dbo].[DeleteTblKolMoin]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteTblKolMoin', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteTblKolMoin] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc  [dbo].[DeleteTblKolMoin]
@ID as int

as
begin
Delete from tblKolMoin Where ID=@ID
end
GO

-- ===============================================
-- SP: [dbo].[DeleteTblTarheTakhfif]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteTblTarheTakhfif', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteTblTarheTakhfif] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc  [dbo].[DeleteTblTarheTakhfif]
@ID as int

as
begin
Delete from tblTarheTakhfif Where ID=@ID
end
GO

-- ===============================================
-- SP: [dbo].[DeletetblTarheTakhfifeRadifi]
-- ===============================================
IF OBJECT_ID(N'dbo.DeletetblTarheTakhfifeRadifi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeletetblTarheTakhfifeRadifi] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc  [dbo].[DeletetblTarheTakhfifeRadifi]
@ID as int

as
begin
Delete from tblTarheTakhfifeRadifi Where ID=@ID
end
GO

-- ===============================================
-- SP: [dbo].[DeleteTblVahed]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteTblVahed', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteTblVahed] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc  [dbo].[DeleteTblVahed]
@ID as int

as
begin
Delete from tblVahed Where ID=@ID
end
GO

-- ===============================================
-- SP: [dbo].[DeleteUser]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteUser', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteUser] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[DeleteVam]
-- ===============================================
IF OBJECT_ID(N'dbo.DeleteVam', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[DeleteVam] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[DeleteVam]

@ShomareVam bigint
as 

begin


begin try
begin transaction

declare @code bigint = (select fldShomareSanad from tblVamInfo where fldShomareVam = @ShomareVam)

	delete from tblVamInfo Where fldShomareVam=@ShomareVam
	delete from tblDaftarcheAghsat Where fldShomareVam=@ShomareVam
	delete from tblSodooreSanad where fldSanad = @code
	delete from tblMadarekeVam Where fldShomareVam=@ShomareVam

commit
end try

begin catch

	rollback

end catch

end
GO

-- ===============================================
-- SP: [dbo].[ExistCodeAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.ExistCodeAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ExistCodeAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

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

-- ===============================================
-- SP: [dbo].[ExistFactorBargashtAzForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.ExistFactorBargashtAzForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ExistFactorBargashtAzForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ExistFactorBargashtAzKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.ExistFactorBargashtAzKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ExistFactorBargashtAzKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ExistFactorForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.ExistFactorForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ExistFactorForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ExistFactorKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.ExistFactorKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ExistFactorKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ExistFactorPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.ExistFactorPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ExistFactorPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ExistFactorPishPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.ExistFactorPishPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ExistFactorPishPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ExistShomareAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.ExistShomareAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ExistShomareAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ExistShomareAmani]
	@fldShomareAmani bigint,
	@fldMax bigint output
AS
BEGIN
	set @fldMax=( SELECT top 1 fldShomareAmani  from tblRizeForoosh where fldShomareAmani=@fldShomareAmani)
	if @fldMax is null
		set @fldMax=0
	
END
GO

-- ===============================================
-- SP: [dbo].[ExistShomareBargashtAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.ExistShomareBargashtAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ExistShomareBargashtAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ExistShomareBargashtAmani]
	@fldShomareAmani bigint,
	@fldMax bigint output
AS
BEGIN
	set @fldMax=( SELECT top 1 fldShomareBargashtAmani  from tblRizeBargashtAzForoosh where fldShomareBargashtAmani=@fldShomareAmani)
	if @fldMax is null
		set @fldMax=0
	
END
GO

-- ===============================================
-- SP: [dbo].[ExistShomareEnteghal]
-- ===============================================
IF OBJECT_ID(N'dbo.ExistShomareEnteghal', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ExistShomareEnteghal] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ExistShomareVosool]
-- ===============================================
IF OBJECT_ID(N'dbo.ExistShomareVosool', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ExistShomareVosool] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[Fillter_tbl_DaftarcheTell_ByName_ByTell_NotHas_CodeTafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.Fillter_tbl_DaftarcheTell_ByName_ByTell_NotHas_CodeTafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Fillter_tbl_DaftarcheTell_ByName_ByTell_NotHas_CodeTafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[Filter_Tbl_Tafsili_in_Form_Enteghal_Kala]
-- ===============================================
IF OBJECT_ID(N'dbo.Filter_Tbl_Tafsili_in_Form_Enteghal_Kala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Filter_Tbl_Tafsili_in_Form_Enteghal_Kala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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 + '%' and fldCodeNoe=1
       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 + '%' and fldCodeNoe=1

 end
end
GO

-- ===============================================
-- SP: [dbo].[Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili_WithUserCode]
@codeTafzili nvarchar(20),
@flagSearch int,
@userCode bigint
as
begin

-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################
-- ##########################################################

if (@flagSearch=0)
   begin
            SELECT DISTINCT fldCodeTafzili, fldCodeGroup, fldCodeGroup2, fldSharheTafzili,fldAddress,fldBlackList,
                fldCity,fldCodeEghtesadi,flddescription, fldCodeMeli,fldCodePosti,fldDate1,fldDate2,
                fldPic,fldOstan,fldShomareHesab,fldShomareSabt,
				fldVisitor,fldSharhBlackList,fldSaghfeEtebar,fldHaghighi,fldNoeSooratMoadian, fldName,fldShobe,fldCodeNaghsh
				
            FROM            dbo.tblTafzili 

            where fldCodeTafzili like '%' + @codeTafzili + '%' and fldCodeNoe=1
			and fldCodeTafzili in (select code from @accessCodes)
       end

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

		    where fldSharheTafzili like '%' + @codeTafzili + '%' and fldCodeNoe=1
			and fldCodeTafzili in (select code from @accessCodes)

 end
end
GO

-- ===============================================
-- SP: [dbo].[FilterByCodeAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.FilterByCodeAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[FilterByCodeAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

-- ===============================================
-- SP: [dbo].[FilterByNameAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.FilterByNameAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[FilterByNameAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

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

-- ===============================================
-- SP: [dbo].[FilterDasteCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.FilterDasteCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[FilterDasteCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[FindMaxCodeGroupAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.FindMaxCodeGroupAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[FindMaxCodeGroupAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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,len(@id)-2)
	select max(fldGroupId) from tblGroupAshkhas
	where len(fldGroupId)=len(@id)
	and convert(nvarchar,fldGroupId) like @idSub +'%'
end
END
GO

-- ===============================================
-- SP: [dbo].[FindMaxCodeGroupKala]
-- ===============================================
IF OBJECT_ID(N'dbo.FindMaxCodeGroupKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[FindMaxCodeGroupKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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,len(@id)-2)
	select max(fldGroupId) from tblGroupKala
	where len(fldGroupId)=len(@id)
	and convert(nvarchar,fldGroupId) like @idSub +'%'
end
END
GO

-- ===============================================
-- SP: [dbo].[GetCodeVahedByName]
-- ===============================================
IF OBJECT_ID(N'dbo.GetCodeVahedByName', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetCodeVahedByName] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetCodeVaseteByCodeTafsili]
-- ===============================================
IF OBJECT_ID(N'dbo.GetCodeVaseteByCodeTafsili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetCodeVaseteByCodeTafsili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetfldTedadInYekCarton]
-- ===============================================
IF OBJECT_ID(N'dbo.GetfldTedadInYekCarton', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetfldTedadInYekCarton] AS BEGIN SET NOCOUNT ON; END')
END
GO

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


END
GO

-- ===============================================
-- SP: [dbo].[GetGhymatMasrafkonande]
-- ===============================================
IF OBJECT_ID(N'dbo.GetGhymatMasrafkonande', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetGhymatMasrafkonande] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

-- ===============================================
-- SP: [dbo].[GetInfoKala]
-- ===============================================
IF OBJECT_ID(N'dbo.GetInfoKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetInfoKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetListEshantionAshkhasTabalaghti]
-- ===============================================
IF OBJECT_ID(N'dbo.GetListEshantionAshkhasTabalaghti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetListEshantionAshkhasTabalaghti] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[GetListEshantionAshkhasTabalaghti]

@CodeTafzili nvarchar(10),
@CodeKala bigint
as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin

SELECT        TOP (200) tblEshantionAshkhasTabaghati.fldShomareTabaghe, tblEshantionAshkhasTabaghati.fldTedadForoosh, tblEshantionAshkhasTabaghati.fldCodeKalaEshantion, tblEshantionAshkhasTabaghati.fldTedadEshantion, 
                          tblKala_1.fldNameKala AS fldNameKalaEshantion
FROM            tblEshantionAshkhasTabaghati INNER JOIN
                         tblKala ON tblEshantionAshkhasTabaghati.fldCodeKalaForoosh = tblKala.fldCodeKala INNER JOIN
                         tblKala AS tblKala_1 ON tblEshantionAshkhasTabaghati.fldCodeKalaEshantion = tblKala_1.fldCodeKala
	where tblEshantionAshkhasTabaghati.fldCodeKalaForoosh=@CodeKala and tblEshantionAshkhasTabaghati.fldcodetafzili=@CodeTafzili
	order by fldShomareTabaghe
	
end
GO

-- ===============================================
-- SP: [dbo].[GetListFullInfoKala]
-- ===============================================
IF OBJECT_ID(N'dbo.GetListFullInfoKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetListFullInfoKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetListMultiPrice]
-- ===============================================
IF OBJECT_ID(N'dbo.GetListMultiPrice', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetListMultiPrice] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[GetMablaghHamloNaghl]
-- ===============================================
IF OBJECT_ID(N'dbo.GetMablaghHamloNaghl', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetMablaghHamloNaghl] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetMablaghHamloNaghlBargashtAzKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.GetMablaghHamloNaghlBargashtAzKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetMablaghHamloNaghlBargashtAzKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetMablaghHamloNaghlKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.GetMablaghHamloNaghlKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetMablaghHamloNaghlKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetMaxShomareEnteghal]
-- ===============================================
IF OBJECT_ID(N'dbo.GetMaxShomareEnteghal', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetMaxShomareEnteghal] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[GetMaxShomareEnteghal]
	@fldMax bigint output
AS
BEGIN
	
	set @fldMax=( SELECT isnull(max(fldShomareEnteghal),0) as fldMax from tblRizeForoosh)
END
GO

-- ===============================================
-- SP: [dbo].[GetMaxShomareFactorBargashtAzForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.GetMaxShomareFactorBargashtAzForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetMaxShomareFactorBargashtAzForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

-- ===============================================
-- SP: [dbo].[GetMaxShomareFactorBargashtAzKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.GetMaxShomareFactorBargashtAzKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetMaxShomareFactorBargashtAzKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

-- ===============================================
-- SP: [dbo].[GetMaxShomareFactorForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.GetMaxShomareFactorForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetMaxShomareFactorForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

-- ===============================================
-- SP: [dbo].[GetMaxShomareFactorKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.GetMaxShomareFactorKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetMaxShomareFactorKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

-- ===============================================
-- SP: [dbo].[GetMaxShomareFactorPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.GetMaxShomareFactorPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetMaxShomareFactorPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

-- ===============================================
-- SP: [dbo].[GetMaxShomareFactorPishPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.GetMaxShomareFactorPishPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetMaxShomareFactorPishPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

-- ===============================================
-- SP: [dbo].[GetMaxShomarePishFactorForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.GetMaxShomarePishFactorForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetMaxShomarePishFactorForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

-- ===============================================
-- SP: [dbo].[GetNameGroupByCodeTafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.GetNameGroupByCodeTafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetNameGroupByCodeTafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[GetOtherInfoBargashtAzFactor]
-- ===============================================
IF OBJECT_ID(N'dbo.GetOtherInfoBargashtAzFactor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetOtherInfoBargashtAzFactor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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.tblbargashtAzForoosh.fldShomarePishFactor, 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

-- ===============================================
-- SP: [dbo].[GetOtherInfoFactor]
-- ===============================================
IF OBJECT_ID(N'dbo.GetOtherInfoFactor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetOtherInfoFactor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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.tblForoosh.fldShomarePishFactor, 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

-- ===============================================
-- SP: [dbo].[GetOtherInfoFactorAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.GetOtherInfoFactorAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetOtherInfoFactorAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[GetOtherInfoFactorAmani] 
	@fldShomareFactor bigint
AS
BEGIN
	
	SET NOCOUNT ON;

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

-- ===============================================
-- SP: [dbo].[GetOtherInfoFactorBargashtAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.GetOtherInfoFactorBargashtAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetOtherInfoFactorBargashtAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[GetOtherInfoFactorBargashtAmani] 
	@fldShomareFactor bigint
AS
BEGIN
	
	SET NOCOUNT ON;

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

-- ===============================================
-- SP: [dbo].[GetOtherInfoFactorBargashtAzKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.GetOtherInfoFactorBargashtAzKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetOtherInfoFactorBargashtAzKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetOtherInfoFactorKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.GetOtherInfoFactorKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetOtherInfoFactorKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetOtherInfoPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.GetOtherInfoPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetOtherInfoPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetOtherInfoPishPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.GetOtherInfoPishPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetOtherInfoPishPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetPorsantSuperVisor]
-- ===============================================
IF OBJECT_ID(N'dbo.GetPorsantSuperVisor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetPorsantSuperVisor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[GetPorsantVisitor]
-- ===============================================
IF OBJECT_ID(N'dbo.GetPorsantVisitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetPorsantVisitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[GetRowEshantionKalaAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.GetRowEshantionKalaAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetRowEshantionKalaAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[GetRowEshantionKalaAshkhas]
	@CodeTafzili nvarchar(10),
	@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 tblEshantionAshkhasTabaghati
			  where [fldCodeKalaForoosh]=@lngCodeKala and fldCodeTafzili=@CodeTafzili

END
GO

-- ===============================================
-- SP: [dbo].[GetRowEshantionTabaghati]
-- ===============================================
IF OBJECT_ID(N'dbo.GetRowEshantionTabaghati', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetRowEshantionTabaghati] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetRowEshantionTekrarShavande]
-- ===============================================
IF OBJECT_ID(N'dbo.GetRowEshantionTekrarShavande', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetRowEshantionTekrarShavande] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetShomareDaryaftByfldSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.GetShomareDaryaftByfldSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetShomareDaryaftByfldSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetShomarePardakhtByfldSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.GetShomarePardakhtByfldSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetShomarePardakhtByfldSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetStuffGroupBenefitFifo]
-- ===============================================
IF OBJECT_ID(N'dbo.GetStuffGroupBenefitFifo', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetStuffGroupBenefitFifo] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter Procedure [dbo].[GetStuffGroupBenefitFifo](@DateFROM BIGINT,@DateTo BIGINT, @ListCodeAnbar VARCHAR(5000),@fldCodekala bigint, @fldCodeGroup bigint)
AS
BEGIN
	DECLARE	@LastDurationResult Table([CodeKala] bigint,[CodeGroup] bigint, SumBuyAmount decimal,SumBuyCount bigint,
		SumSellAmount decimal, SumSellCount bigint, SumReSellAmount decimal, SumReSellCount decimal, RemaindCount bigint,
		RemaindAtEnd bigint, StuffRemaindAtEnd bigint, BahayeTamamShodeFifo decimal, Benefit decimal);

	DECLARE	@CurrentDurationResult Table([CodeKala] bigint,[CodeGroup] bigint, SumBuyAmount decimal,SumBuyCount bigint,
	SumSellAmount decimal, SumSellCount bigint, SumReSellAmount decimal, SumReSellCount decimal, RemaindCount bigint,
	RemaindAtEnd bigint, StuffRemaindAtEnd bigint, BahayeTamamShodeFifo decimal, Benefit decimal);

	DECLARE	@AllDurationResult Table([CodeKala] bigint,[CodeGroup] bigint, SumBuyAmount decimal,SumBuyCount bigint,
		SumSellAmount decimal, SumSellCount bigint, SumReSellAmount decimal, SumReSellCount decimal, RemaindCount bigint,
		RemaindAtEnd bigint, StuffRemaindAtEnd bigint, BahayeTamamShodeFifo decimal, Benefit decimal);


	INSERT INTO @CurrentDurationResult
	EXEC	[SoodeGroupFifo] @DateFrom, @DateTo, @ListCodeAnbar,@fldCodekala, @fldCodeGroup
	
	DECLARE @endDate bigint = @DateFROM -1

	INSERT INTO @LastDurationResult
	EXEC	[SoodeGroupFifo] 0, @endDate, @ListCodeAnbar,@fldCodekala, @fldCodeGroup

		
	INSERT INTO @AllDurationResult
	EXEC	[SoodeGroupFifo] 0,@DateTo , @ListCodeAnbar,@fldCodekala, @fldCodeGroup

	SELECT	Row_NUMBER() Over (ORDER BY [Current].[CodeKala]) [RowNo],[Current].[CodeKala], [STUFF].fldNameKala StuffName, [Current].[CodeGroup],  [StuffGroup].fldGroupName GroupName,[Current].SumBuyAmount,
			[Current].SumBuyCount, [Current].SumSellAmount,
			[Current].SumSellCount, [Current].SumReSellAmount, [Current].SumReSellCount, [Current].RemaindCount,
			isnull([Current].RemaindAtEnd,0) RemaindAtEnd, [Current].StuffRemaindAtEnd, [Current].BahayeTamamShodeFifo,
			(ISNULL([ALL].Benefit,0) - ISNULL([Last].Benefit,0)) Benefit
	FROM	@CurrentDurationResult [Current]
			LEFT JOIN @AllDurationResult [All] ON [Current].CodeKala=[All].CodeKala
			LEFT JOIN @LastDurationResult [Last] ON [Current].CodeKala=[Last].CodeKala
			INNER JOIN tblKala [Stuff] ON [Current].CodeKala=[Stuff].fldCodeKala
			INNER JOIN tblGroupKala [StuffGroup] ON [Stuff].fldCodeGroup=[StuffGroup].fldGroupId
	ORDER BY [Current].[CodeKala]
END
GO

-- ===============================================
-- SP: [dbo].[GetTanzimatForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.GetTanzimatForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetTanzimatForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[GetTedadJozKala]
-- ===============================================
IF OBJECT_ID(N'dbo.GetTedadJozKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[GetTedadJozKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

-- ===============================================
-- SP: [dbo].[HasAmalkard]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkard', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkard] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[HasAmalkardAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkardAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkardAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[HasAmalkardAnbarNew]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkardAnbarNew', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkardAnbarNew] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[HasAmalkardBankMa]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkardBankMa', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkardBankMa] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[HasAmalkardBankMa] 
	-- 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
	declare @strCodeKoleHesab nvarchar(10)
	execute CodeKolHesab 'bank',@strcodekolehesab output

		set @intCount=(Select Count(fldMoinKamel) from tblSodooreSanad  Where fldMoinKamel=@strcodekolehesab)
	if @intCount>0
		set @Amalkard='true'
	else
		begin
	set @intCount=(Select Count(fldCodeBank) from tblCheckePardakhti Where fldCodeBank=@CodeBank)
	if @intCount>0
		set @Amalkard='true'
	else
		set @Amalkard='false'
		end
END
GO

-- ===============================================
-- SP: [dbo].[HasAmalkardBankMoshtari]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkardBankMoshtari', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkardBankMoshtari] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[HasAmalkardeDaryaftMain]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkardeDaryaftMain', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkardeDaryaftMain] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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
	else
		begin
			set @VaziatVosool=(Select top(1) fldShomarePardakht from tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and fldShomarePardakht is not null)	
			if @VaziatVosool is not null
				set @Khorooji=	'forooshecheck'
		end

		
		
end
GO

-- ===============================================
-- SP: [dbo].[HasAmalkardePardakhtMain]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkardePardakhtMain', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkardePardakhtMain] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[HasAmalkardKala]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkardKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkardKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

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

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

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

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

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

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

END
GO

-- ===============================================
-- SP: [dbo].[HasAmalkardKolMoin]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkardKolMoin', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkardKolMoin] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[HasAmalkardSandoogh]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkardSandoogh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkardSandoogh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[HasAmalkardSandoogh] 
	-- Add the parameters for the stored procedure here
	@CodeSandoogh bigint,
	@Amalkard nvarchar(10) output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	declare @intCount bigint
	declare @strCodeKoleHesab nvarchar(10)


		set @intCount=(Select Count(fldMoinKamel) from tblSodooreSanad  Where fldMoinKamel=@CodeSandoogh)
	if @intCount>0
		set @Amalkard='true'
	else
		set @Amalkard='false'
		
END
GO

-- ===============================================
-- SP: [dbo].[HasAmalkardSuperVizor]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkardSuperVizor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkardSuperVizor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[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

-- ===============================================
-- SP: [dbo].[HasAmalkardVizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.HasAmalkardVizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HasAmalkardVizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[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 or fldVasete=@CodeTafzili)
			if @bigCount>0 				
				set @strHasAmalkard='true'						
				

	set @bigCount=(Select count(id) from tblSodooreSanad where fldVasete=@CodeTafzili)
	if @bigCount>0 
		set @strHasAmalkard='true'


	set @bigCount=(Select count(id) from tblCheckeDaryafti where fldVasete=@CodeTafzili)
		if @bigCount>0 
			set @strHasAmalkard='true'

	set @bigCount=(Select count(id) from tblTafzili where fldVisitor=@CodeTafzili)
		if @bigCount>0 
			set @strHasAmalkard='true'


END
GO

-- ===============================================
-- SP: [dbo].[HesabeHazinePardakht]
-- ===============================================
IF OBJECT_ID(N'dbo.HesabeHazinePardakht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HesabeHazinePardakht] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[HesabeHazinePardakht] 
	@ShomareSanad bigint,
	@CodeKolHazine nvarchar(10),
	@CodeKolMoinHazine nvarchar(10) output,
	@SharheHesab nvarchar(50) output

AS
BEGIN
	set @CodeKolMoinHazine=(Select  top(1)fldMoinKamel from tblSodooreSanad Where fldSanad=@ShomareSanad and fldCodeKol like @CodeKolHazine + '%')
	set @SharheHesab=(Select  top(1)fldSharheHesab from tblKolMoin Where fldCodeHesab=@CodeKolMoinHazine)
END
GO

-- ===============================================
-- SP: [dbo].[HesabeSandooghBankPardakht]
-- ===============================================
IF OBJECT_ID(N'dbo.HesabeSandooghBankPardakht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[HesabeSandooghBankPardakht] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[IDOfPrinter]
-- ===============================================
IF OBJECT_ID(N'dbo.IDOfPrinter', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[IDOfPrinter] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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 top(1) id from tblPrinters Where fldNamePrinter=@NamePrinter )
    if @id1 is null
		set @IDPrinter=0
	else
		set @IDPrinter =@ID1
END
GO

-- ===============================================
-- SP: [dbo].[InfoPoorsantVizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.InfoPoorsantVizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InfoPoorsantVizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[InfoPoorsantVizitor] 
	@CodeTafzili nvarchar(10),
	@fldNoeMohasebePoorsant int output,
	@fldCodeSuperVisor nvarchar(10) output,
	@fldPoorsant decimal(18,2) 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 isnull(fldCodeSuperVisor ,'') from tblTafzili Where fldCodeTafzili = @CodeTafzili)
	set @fldPoorsant=(Select fldPoorsant from tblTafzili Where fldCodeTafzili = @CodeTafzili)
	
END
GO

-- ===============================================
-- SP: [dbo].[Insert_Tbl_DaftarcheTell]
-- ===============================================
IF OBJECT_ID(N'dbo.Insert_Tbl_DaftarcheTell', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Insert_Tbl_DaftarcheTell] AS BEGIN SET NOCOUNT ON; END')
END
GO

/****** Object:  StoredProcedure [dbo].[checkIdNumber_GruopAshkhas]    Script Date: 09/30/2019 11:52:52 ق.ظ ******/
Alter 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 (fldCodeTafzili, fldName, fldShomare, fldSms, fldSharh)
values(
 @fldCodeTafzili,
 @fldName,
 @fldShomare,
 @fldSms,
 @fldSharh) 
 
set @flagsabt=1
end
GO

-- ===============================================
-- SP: [dbo].[Insert_Tbl_DaftarcheTell_has_CodeTafsili]
-- ===============================================
IF OBJECT_ID(N'dbo.Insert_Tbl_DaftarcheTell_has_CodeTafsili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Insert_Tbl_DaftarcheTell_has_CodeTafsili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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( fldCodeTafzili, fldName, fldShomare, fldSms, fldSharh)
values(
 @fldCodeTafzili,
 @fldName,
 @fldShomare,
 @fldSms,
 @fldSharh) 
 
set @flagsabt=1
end
GO

-- ===============================================
-- SP: [dbo].[Insert_Tbl_Tafzili_final]
-- ===============================================
IF OBJECT_ID(N'dbo.Insert_Tbl_Tafzili_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Insert_Tbl_Tafzili_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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 decimal(18,2),
@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

-- ===============================================
-- SP: [dbo].[Insert_Tbl_Tafzili_final_2]
-- ===============================================
IF OBJECT_ID(N'dbo.Insert_Tbl_Tafzili_final_2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Insert_Tbl_Tafzili_final_2] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Insert_Tbl_Tafzili_final_2]
@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),	
@fldDescription nvarchar(250),
@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 decimal(18,2),
@fldCodeSuperVisor nvarchar(10),
@fldNoeMohasebePoorsant int,
@fldDarsadTakhfif decimal(18,2),
@fldHaghighi int,
@NoeSooratMoadian int,
@fldName nvarchar(30),
@fldShobe nvarchar(15),
@fldCodeNaghsh nvarchar(20),
@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,fldDescription,
				fldCodePosti,fldShomareSabt,fldSaghfeEtebar,
				fldBlackList,fldSharhBlackList,
				fldDate1,fldDate2,
				fldVisitor,
				fldPic,fldNoeVizitor,fldPoorsant,fldCodeSuperVisor,fldNoeMohasebePoorsant,fldDarsadtakhfif,fldHaghighi,fldNoeSooratMoadian,fldName,fldShobe,fldCodeNaghsh)

				values (@fldNoeHesab,@fldSharheTafzili,@Convert_TafziliCode_Create,@fldCodeNoe,
				@fldNoe,@fldCodeGroup,@fldOstan,@fldCity,@fldAddress,
				@fldShomareHesab,@fldCodeMeli,@fldCodeEghtesadi,@fldDescription,
				@fldCodePosti,@fldShomareSabt,@fldSaghfeEtebar,
				@fldBlackList,@fldSharhBlackList,
				@fldDate1,@fldDate2,
				@fldVisitor,
				@fldPic,@fldNoeVizitor,@fldPoorsant,@fldCodeSuperVisor,@fldNoeMohasebePoorsant,@fldDarsadTakhfif,@fldHaghighi,@NoeSooratMoadian ,@fldName,@fldShobe,@fldCodeNaghsh)
              
			  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,fldDescription,
				fldCodePosti,fldShomareSabt,fldSaghfeEtebar,
				fldBlackList,fldSharhBlackList,
				fldDate1,fldDate2,
				fldVisitor,
				fldPic,fldNoeVizitor,fldPoorsant,fldCodeSuperVisor,fldNoeMohasebePoorsant,fldDarsadtakhfif,fldHaghighi,fldNoeSooratMoadian,fldName,fldShobe,fldCodeNaghsh)
values (@fldNoeHesab,@fldSharheTafzili,@Convert_TafziliCode_Create2,@fldCodeNoe,
@fldNoe,@fldCodeGroup,@fldOstan,@fldCity,@fldAddress,
@fldShomareHesab,@fldCodeMeli,@fldCodeEghtesadi,@fldDescription,
@fldCodePosti,@fldShomareSabt,@fldSaghfeEtebar,
@fldBlackList,@fldSharhBlackList,
@fldDate1,@fldDate2,
@fldVisitor,
@fldPic,@fldNoeVizitor,@fldPoorsant,@fldCodeSuperVisor,@fldNoeMohasebePoorsant,@fldDarsadtakhfif,@fldHaghighi,@NoeSooratMoadian,@fldName,@fldShobe,@fldCodeNaghsh)

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

END
GO

-- ===============================================
-- SP: [dbo].[Insert_Tbl_Tafzili_final_3]
-- ===============================================
IF OBJECT_ID(N'dbo.Insert_Tbl_Tafzili_final_3', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Insert_Tbl_Tafzili_final_3] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Insert_Tbl_Tafzili_final_3]
@fldNoeHesab	nvarchar(15),	
@fldSharheTafzili	nvarchar(200),
@fldCodeTafzili	nvarchar(10),	
@fldCodeNoe	nvarchar(5),	--set "1"
@fldNoe	nvarchar(10),	
@fldCodeGroup	bigint,	      
@fldCodeGroup2   bigint,
@fldOstan	nvarchar(50),	
@fldCity	nvarchar(50),	
@fldAddress	nvarchar(200),	
@fldShomareHesab	nvarchar(20),	
@fldCodeMeli	nvarchar(20),	
@fldCodeEghtesadi	nvarchar(20),	
@fldDescription nvarchar(250),
@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 decimal(18,2),
@fldCodeSuperVisor nvarchar(10),
@fldNoeMohasebePoorsant int,
@fldDarsadTakhfif decimal(18,2),
@fldHaghighi int,
@NoeSooratMoadian int,
@fldName nvarchar(30),
@fldShobe nvarchar(15),
@fldCodeNaghsh nvarchar(20),
@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,fldCodeGroup2,fldOstan,fldCity,fldAddress,
				fldShomareHesab,fldCodeMeli,fldCodeEghtesadi,fldDescription,
				fldCodePosti,fldShomareSabt,fldSaghfeEtebar,
				fldBlackList,fldSharhBlackList,
				fldDate1,fldDate2,
				fldVisitor,
				fldPic,fldNoeVizitor,fldPoorsant,fldCodeSuperVisor,fldNoeMohasebePoorsant,fldDarsadtakhfif,fldHaghighi,fldNoeSooratMoadian,fldName,fldShobe,fldCodeNaghsh)

				values (@fldNoeHesab,@fldSharheTafzili,@Convert_TafziliCode_Create,@fldCodeNoe,
				@fldNoe,@fldCodeGroup,@fldCodeGroup2,@fldOstan,@fldCity,@fldAddress,
				@fldShomareHesab,@fldCodeMeli,@fldCodeEghtesadi,@fldDescription,
				@fldCodePosti,@fldShomareSabt,@fldSaghfeEtebar,
				@fldBlackList,@fldSharhBlackList,
				@fldDate1,@fldDate2,
				@fldVisitor,
				@fldPic,@fldNoeVizitor,@fldPoorsant,@fldCodeSuperVisor,@fldNoeMohasebePoorsant,@fldDarsadTakhfif,@fldHaghighi,@NoeSooratMoadian ,@fldName,@fldShobe,@fldCodeNaghsh)
              
			  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
------------------------------------------------------------
if isnumeric(@fldCodeTafzili)=1 
	begin
		declare @cnt int
		set @cnt=(select count(fldCodetafzili) from tblTafzili where fldCodeTafzili=@fldCodeTafzili)
		if @cnt>0
			begin
				set @flagSabtOK=-1
				return
			end
		else
			set @MaxCodeTafzili=@fldCodeTafzili
	end
else
	set @MaxCodeTafzili=@MaxCodeTafzili+1

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

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

END
GO

-- ===============================================
-- SP: [dbo].[Insert_Tbl_Tafzili_Personel]
-- ===============================================
IF OBJECT_ID(N'dbo.Insert_Tbl_Tafzili_Personel', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Insert_Tbl_Tafzili_Personel] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Insert_Tbl_Tafzili_Personel]
@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,
@fldNoePersonel nvarchar(20),
@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,fldNoePersonel)

				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,@fldNoePersonel)
              
			  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,fldNoePersonel)
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,@fldNoePersonel)

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

END
GO

-- ===============================================
-- SP: [dbo].[InsertAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertAnbar]

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

begin
	set @IDAnbar= (Select Max(fldCode) from tblAnbar where fldCode<2000)

	if ISNUMERIC(@IDAnbar)=1
		Set @IDAnbar+=1
	else
		Set @IDAnbar=1000

	--insert into tblAnbar ()
	--	values(@IDAnbar,@NameAnbar)

	INSERT INTO tblAnbar
            (fldCode, fldNameAnbar, fldCodeposti)
		VALUES        (@IDAnbar,@NameAnbar,@Codeposti)
	set @flagSabt=@IDAnbar
	set @IDOutPut=@@IDENTITY
end
GO

-- ===============================================
-- SP: [dbo].[InsertAnbarAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertAnbarAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertAnbarAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertAnbarAmani]

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

begin
	set @IDAnbar= (Select Max(fldCode) from tblAnbar where fldCode>=2000)

	if ISNUMERIC(@IDAnbar)=1
		Set @IDAnbar+=1
	else
		Set @IDAnbar=2000

	insert into tblAnbar 
			(fldCode, fldNameAnbar)
		values(@IDAnbar,@NameAnbar)

	insert into tblAnbarAmani
		(fldCodeAnbar,fldCodeTafzili)
		values	(@IDAnbar,@CodeTafzili)

	set @flagSabt=@IDAnbar
	set @IDOutPut=@@IDENTITY
end
GO

-- ===============================================
-- SP: [dbo].[InsertBank]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertBank', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertBank] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertBank]

@IDHesab bigInt,
@NameHesab nvarChar(70),
@CodeKolHesab nvarChar(8),
@CodeType nvarchar(5),
@SharheNoeTafzili nvarchar(20),
@ShomareHesab nvarchar(50),
@Mande decimal(18,0),
@fldDate bigint,
@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 
				 ( fldCodeHesab, fldSharheHesab, fldNoeHesab, fldCodeNoeHesab, fldMarkazFirst, fldMarkazSecond, fldNoe, fldInfo)
		values(@IDHesab,@NameHesab,@SharheNoeTafzili,@CodeType,'غير فعال','غير فعال',null,@ShomareHesab)


		--#################################INSERT SANAD####################################
		if @Mande>0
			begin
				declare @TooleKol bigint,@Toolemoin bigint,@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@yearFull int,@year int,@month int,@day int,@fldShomareSanad bigint,@fldCodeKolSarmaye int
				execute  ToolePaye 'kol',@TooleKol output
				execute  ToolePaye 'moin',@Toolemoin output
				--execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
				set @CodeKolkham =substring(convert(varchar,@IDHesab), 1, @TooleKol)
				set @CodeMoinKham =substring(convert(varchar,@IDHesab),@TooleKol+1,@Toolemoin)

				set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
				set @year=@yearFull
				set @month=substring(convert(nvarchar(20),@fldDate),5,2)
				set @day=substring(convert(nvarchar(20),@fldDate),7,2)

				execute CodeKolHesab 'sarmaye',@fldCodeKolSarmaye output

				delete from tblSodooreSanad where fldType='mandebank' and fldMoinKamel=@IDHesab

				execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@IDHesab,'','1',@Mande,0,1,@fldDate,'مانده ابتدای دوره بانک',@day,@month,@year,'mandebank','',@fldShomareSanad output 
				execute InsertSanadLast @fldCodeKolSarmaye,'',@fldCodeKolSarmaye,'','',0,@Mande,2,@fldDate,'مانده ابتدای دوره بانک',@day,@month,@year,'mandebank','',@fldShomareSanad
			end
		--#################################################################################

	set @flagSabt=@IDHesab
	set @IDOutPut=@@IDENTITY
end
GO

-- ===============================================
-- SP: [dbo].[InsertBankeMa]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertBankeMa', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertBankeMa] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[InsertBankeMa]
@NameBank nvarchar(50),
@intCode int output,
@idSabt int output
as
begin
		declare @strCodeKoleHesab nvarchar(10)
		execute CodeKolHesab 'bank',@strcodekolehesab output

		execute InsertKolMoin '1000',@NameBank,@strCodeKoleHesab,'تفصيلي ندارد','4',@intCode,@idSabt
end
GO

-- ===============================================
-- SP: [dbo].[InsertBankeMoshtari]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertBankeMoshtari', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertBankeMoshtari] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertBankeMoshtari]

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

begin

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

-- ===============================================
-- SP: [dbo].[insertDasteCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.insertDasteCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[insertDasteCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[insertDasteCheck]
@daste tblDaftarCheck ReadOnly

as

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

-- ===============================================
-- SP: [dbo].[InsertDastrasi]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertDastrasi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertDastrasi] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- Batch submitted through debugger: SQLQuery7.sql|7|0|C:\Users\marashi2\AppData\Local\Temp\~vsD567.sql
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[InsertDastrasiSandoogh]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertDastrasiSandoogh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertDastrasiSandoogh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[InsertDastrasiSandoogh] 
	@CodeUser bigint,
	@CodeSandoogh bigint,
	@CodeBank bigint,	
	@ElzamiSandoogh  nvarchar(5) ,
	@ElzamiBank nvarchar(5) ,
	@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,fldElzamiSandoogh)
			values
			(@CodeUser,@CodeSandoogh,'sandoogh',@ElzamiSandoogh)

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

	commit transaction
	end try

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

	end catch
		
END
GO

-- ===============================================
-- SP: [dbo].[InsertEbtedaDoreh_Ashkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertEbtedaDoreh_Ashkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertEbtedaDoreh_Ashkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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
		    declare @DateSanad nvarchar(20),@day  nvarchar(20),@month  nvarchar(20),@year nvarchar(20)
			set @DateSanad=(select top(1) flddate from @dtSanadEbteda_Ashkas )
			set @year=SUBSTRING(@DateSanad,1,4)
			set @month=SUBSTRING(@DateSanad,5,2)
			set @day=SUBSTRING(@DateSanad,7,2)
		    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,fldDate,fldDay,fldMonth,fldYear)
									values (@fldShmareSanad,@fldCodeKolSarmaye,@fldMoinKamelSarmaye,
											@fldBedehkar,@fldBestankar,@fldRadif,'EbtedaAshkhas','',@DateSanad,@day,@month,@year)


							     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,fldDate,fldDay,fldMonth,fldYear)
									values (@fldShmareSanad,@fldCodeKolSarmaye,@fldMoinKamelSarmaye,
											@fldBedehkar,@fldBestankar,@fldRadif,'EbtedaAshkhas','',@DateSanad,@day,@month,@year)

				
							     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

-- ===============================================
-- SP: [dbo].[insertGroupAshkhas_m]
-- ===============================================
IF OBJECT_ID(N'dbo.insertGroupAshkhas_m', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[insertGroupAshkhas_m] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- Batch submitted through debugger: SQLQuery16.sql|7|0|C:\Users\ALISER~1\AppData\Local\Temp\~vsF5E.sql
Alter 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(fldGroupId,fldGroupName)
		     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(fldGroupId,fldGroupName)
		     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) + '%' )

				 
				 declare @Name nvarchar(100)
				 set @Name=(select top(1) fldGroupName  from tblGroupAshkhas where fldGroupName=@fldGroupAshkhasName And Convert(varchar,fldGroupId) like  left(convert(varchar,@fldGroupAshkhasId),len(convert(varchar,@fldGroupAshkhasId))-3) + '%')  -- len(fldGroupId)=len(@fldGroupAshkhasId))
				 --if not Exists(select fldGroupName  from tblGroupAshkhas where fldGroupName=@fldGroupAshkhasName And len(fldGroupId)=len(@fldGroupAshkhasId) )
				 if @name is  null
					 begin
						set @idnumber=@idnumber+1
						
						
							 insert into tblGroupAshkhas(fldGroupId,fldGroupName)
								 values(@idnumber,@fldGroupAshkhasName)
								 
					 end
				 else
					 begin
					  set @flag=1 -- نام کالا در آن سطح مشابه میباشد
					  return
					 end
		
		   end
		 

		      end
GO

-- ===============================================
-- SP: [dbo].[insertGroupKala_m]
-- ===============================================
IF OBJECT_ID(N'dbo.insertGroupKala_m', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[insertGroupKala_m] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- Batch submitted through debugger: SQLQuery16.sql|7|0|C:\Users\ALISER~1\AppData\Local\Temp\~vsF5E.sql
Alter 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(fldGroupId,fldGroupName)
		     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(fldGroupId,fldGroupName)
		     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 LEN(fldGroupId) =len(@fldGroupKalaId) and convert(nvarchar(50),fldGroupId) like  substring(convert(nvarchar,@fldGroupKalaId),1,len(@fldGroupKalaId)-3) + '%' )
				 
				  --and not Exists(select fldGroupId  from tblGroupKala where fldGroupId=@fldGroupKalaId)
					 begin
						set @idnumber=@idnumber+1
						
						
							 insert into tblGroupKala(fldGroupId,fldGroupName)
								 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

-- ===============================================
-- SP: [dbo].[InsertInfoAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[InsertInfoAmani]
	@dtForoosh tpRizeForoosh_Amani2 readonly,
	@dtKharid tpRizeKharid_EnteghalNew readonly,
	@fldShomareAmani bigint,
	@fldCodeAnbar_in bigint,
	@fldCodeAshkhas_in bigint,
	@InsertType nvarchar(50),
	@strResult nvarchar(25) output  
	
AS
BEGIN

	SET NOCOUNT ON;

        begin transaction AddRecord
             declare @lngCountAmani bigint
			 declare @Date bigint, @CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@CodeMoin nvarchar(10),@decMablaghKolFactor decimal(18,0),@intRadif bigint,@dateSmall nvarchar(10),@day nvarchar(10),@month nvarchar(10),@year nvarchar(10),@TooleKol bigint,@Toolemoin bigint,@fldCodeVasete bigint,@strSharhKoli nvarchar(250),@fldShomareSanad bigint
             begin try  --try
							  set @fldCodeVasete=(select top(1) fldCodeVasete from @dtForoosh)	
			                  set @lngCountAmani=(Select Count(fldShomareAmani) from tblRizeForoosh Where fldShomareAmani=@fldShomareAmani)
							  set @decMablaghKolFactor=(Select Sum(fldMablaghKhales ) from @dtForoosh)
					          if ( @lngCountAmani = 0)
							    begin
									--INSERT INTO tblTest7(fld1, fld2, fld3)
									--					VALUES        ('2',2,2)

									if @InsertType='insert'
									  begin

									    execute  ToolePaye 'kol',@TooleKol output
										execute  ToolePaye 'moin',@Toolemoin output
										execute codemoinhesab 'forooshamani' ,@CodeMoin output
										set @CodeKolkham =substring(@CodeMoin, 1, @TooleKol)
										set @CodeMoinKham =substring(@CodeMoin,@TooleKol+1,@Toolemoin)											
										--set @dateSmall=(Select Top(1) substring(Convert(varchar,fldDate),3,6)  from @dtForoosh)
										set @Date=(Select Top(1) fldDate  from @dtForoosh)
										set @year=substring(convert(nvarchar(20),@Date),1,4)
										--set @yearFull=substring(convert(nvarchar(20),@Date),0,5)
										set @month=substring(convert(nvarchar(20),@Date),5,2)
										set @day=substring(convert(nvarchar(20),@Date),7,2)
										set @dateSmall=substring(convert(nvarchar(15),@Date),1,8)


										execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoin,@fldCodeAshkhas_in,'1',@decMablaghKolFactor,0,1,@dateSmall,@strSharhKoli,@day,@month,@year,'amani',@fldCodeVasete,@fldShomareSanad output 

										execute CodeKolHesab'tarafeentezami' ,@CodeMoin output
										set @CodeKolkham =substring(@CodeMoin, 1, @TooleKol)
										set @CodeMoinKham =substring(@CodeMoin,@TooleKol+1,@Toolemoin)
										execute InsertSanadLast  @CodeKolkham,@CodeMoinKham,@CodeMoin,NULL,NULL,0,@decMablaghKolFactor,2,@dateSmall,@strSharhKoli,@day,@month,@year,'amani',@fldCodeVasete,@fldShomareSanad
									  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]
										   ,[fldShomareAmani]
										   ,[fldDateEngheza])
											SELECT
											@fldShomareSanad
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]	
										   ,@fldCodeAshkhas_in								   
										   ,[fldCodeUser]
										   ,[fldRadif]		
										   ,[fldCodeAnbar]							   
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]										   
										   ,@fldShomareAmani 
										   ,[fldDateEngheza]
										   output from @dtForoosh


									--ثبت انبار وارده ریز خرید
									   INSERT INTO [dbo].[tblRizeKharid]
												(
												--[fldCodeTafsili]
												--,[fldCodeUser]
												--,[fldRadif]
												--,[fldCodeAnbar]
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,[fldShomareAmani]
											[fldShomareSanad]
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,[fldCodeTafsili]
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,[fldCodeAnbar]
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,[fldShomareAmani]
										   ,[fldDateEngheza])
												select
												--@fldCodeAshkhas_in
												--,[fldCodeUser]
												--,[fldRadif]
												--,@fldCodeAnbar_in
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,@fldShomareAmani
											@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]
										   ,@fldShomareAmani 
										   ,[fldDateEngheza]
												output from @dtKharid;
											
											--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 @strResult='insertOk'

										end --flag insert
									end --count rowShomare Amani

							--set @lngCountAmani=(Select Count(fldShomareAmani) from tblRizeForoosh Where fldShomareAmani=@fldShomareAmani)
							if ( @lngCountAmani > 0)
									begin
										if @InsertType='arshive'
										  begin

											set @fldShomareSanad=(Select top(1) fldShomareSanad from tblRizeForoosh where fldShomareAmani=@fldShomareAmani and fldType='amani')
											delete from tblRizeForoosh where fldShomareAmani=@fldShomareAmani and fldType='amani'
											delete from tblRizeKharid where fldShomareAmani=@fldShomareAmani and fldType='amani'
											delete from tblSodooreSanad where @fldShomareSanad=@fldShomareSanad and fldType='amani'

											--INSERT       INTO              tblTest7(fld1, fld2, fld3)
											--			VALUES        ('1',1,1)

											execute  ToolePaye 'kol',@TooleKol output
											execute  ToolePaye 'moin',@Toolemoin output
											execute codemoinhesab 'forooshamani' ,@CodeMoin output
											set @CodeKolkham =substring(@CodeMoin, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoin,@TooleKol+1,@Toolemoin)											
											
											set @Date=(Select Top(1) fldDate  from @dtForoosh)
											set @year=substring(convert(nvarchar(20),@Date),1,4)
											
											set @month=substring(convert(nvarchar(20),@Date),5,2)
											set @day=substring(convert(nvarchar(20),@Date),7,2)
											set @dateSmall=substring(convert(nvarchar(15),@Date),1,8)


											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoin,@fldCodeAshkhas_in,'1',@decMablaghKolFactor,0,1,@dateSmall,@strSharhKoli,@day,@month,@year,'amani',@fldCodeVasete,@fldShomareSanad 

											execute CodeKolHesab'tarafeentezami' ,@CodeMoin output
											set @CodeKolkham =substring(@CodeMoin, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoin,@TooleKol+1,@Toolemoin)
											execute InsertSanadLast  @CodeKolkham,@CodeMoinKham,@CodeMoin,NULL,NULL,0,@decMablaghKolFactor,2,@dateSmall,@strSharhKoli,@day,@month,@year,'amani',@fldCodeVasete,@fldShomareSanad

										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]
												,[fldShomareAmani]
												,[fldDateEngheza])
												SELECT
												@fldShomareSanad
												,[fldShomareFactor]
												,[fldCodeVasete]												
												,@fldCodeAshkhas_in
												,[fldCodeUser]
												,[fldRadif]		
												,[fldCodeAnbar]										
												,[fldCodeKala]
												,[fldSharhKala]
												,[fldTedadCarton]
												,[fldTedadJoz]
												,[fldFeeJoz]
												,[fldFeeYekCarton]
												,[fldFeeKol]
												,[fldDarsadTakhfif]
												,[fldMablaghTakhfif]
												,[fldFeeVahed1BadAzTakhfif]
												,[fldFeeVahed2BadAzTakhfif]
												,[fldArzeshAfzode]
												,[fldFeeKolBadAzTakhfif]
												,[fldMablaghKhales]
												,[fldType]
												,[fldDate]
												,[fldTime]
												,@fldShomareAmani 
												,[fldDateEngheza]
												output from @dtForoosh


								--ثبت انبار وارده ریز خرید
												INSERT INTO [dbo].[tblRizeKharid]
															(
												--[fldCodeTafsili]
												--,[fldCodeUser]
												--,[fldRadif]
												--,[fldCodeAnbar]
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,[fldShomareAmani]
											[fldShomareSanad]
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,[fldCodeTafsili]
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,[fldCodeAnbar]
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,[fldShomareAmani]
										   ,[fldDateEngheza])
												select
												--@fldCodeAshkhas_in
												--,[fldCodeUser]
												--,[fldRadif]
												--,@fldCodeAnbar_in
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,@fldShomareAmani
											@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]
										   ,@fldShomareAmani 
										   ,[fldDateEngheza]
												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
			else
				set @strResult='mmm'
		   end catch
   
		END
GO

-- ===============================================
-- SP: [dbo].[InsertInfoBargashAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoBargashAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoBargashAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[InsertInfoBargashAmani]
	@dtForoosh tpRizeForoosh_Amani2 readonly,
	@dtKharid tpRizeKharid_EnteghalNewNew readonly,
	@fldShomareAmani bigint,
	@fldCodeAnbar_Out bigint,
	@fldCodeAshkhas_in bigint,
	@InsertType nvarchar(50),
	@strResult nvarchar(25) output  
	
AS
BEGIN

	SET NOCOUNT ON;

        begin transaction AddRecord
             declare @lngCountAmani bigint
			 declare @Date bigint, @CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@CodeMoin nvarchar(10),@decMablaghKolFactor decimal(18,0),@intRadif bigint,@dateSmall nvarchar(10),@day nvarchar(10),@month nvarchar(10),@year nvarchar(10),@TooleKol bigint,@Toolemoin bigint,@fldCodeVasete bigint,@strSharhKoli nvarchar(250),@fldShomareSanad bigint
             begin try  --try
							  set @fldCodeVasete=(select top(1) fldCodeVasete from @dtForoosh)	
			                  set @lngCountAmani=(Select Count(fldShomareBargashtAmani) from tblRizeBargashtAzForoosh Where fldShomareBargashtAmani=@fldShomareAmani)
							  set @decMablaghKolFactor=(Select Sum(fldMablaghKhales ) from @dtForoosh)
					          if ( @lngCountAmani = 0)
							    begin
									--INSERT INTO tblTest7(fld1, fld2, fld3)
									--					VALUES        ('2',2,2)

									if @InsertType='insert'
									  begin

									    execute  ToolePaye 'kol',@TooleKol output
										execute  ToolePaye 'moin',@Toolemoin output
										execute codemoinhesab 'forooshamani' ,@CodeMoin output
										set @CodeKolkham =substring(@CodeMoin, 1, @TooleKol)
										set @CodeMoinKham =substring(@CodeMoin,@TooleKol+1,@Toolemoin)											
										--set @dateSmall=(Select Top(1) substring(Convert(varchar,fldDate),3,6)  from @dtForoosh)
										set @Date=(Select Top(1) fldDate  from @dtForoosh)
										set @year=substring(convert(nvarchar(20),@Date),1,4)
										--set @yearFull=substring(convert(nvarchar(20),@Date),0,5)
										set @month=substring(convert(nvarchar(20),@Date),5,2)
										set @day=substring(convert(nvarchar(20),@Date),7,2)
										set @dateSmall=substring(convert(nvarchar(15),@Date),1,8)

										
										--execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoin,NULL,NULL,@decMablaghKolFactor,0,1,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtamani',@fldCodeVasete,@fldShomareSanad output

										--execute CodeKolHesab'tarafeentezami' ,@CodeMoin output
										--set @CodeKolkham =substring(@CodeMoin, 1, @TooleKol)
										--set @CodeMoinKham =substring(@CodeMoin,@TooleKol+1,@Toolemoin)
										--execute InsertSanadLast  @CodeKolkham,@CodeMoinKham,@CodeMoin,@fldCodeAshkhas_in,'1',0,@decMablaghKolFactor,2,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtamani',@fldCodeVasete,@fldShomareSanad  
										
										execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoin,@fldCodeAshkhas_in,'1',0,@decMablaghKolFactor,2,@dateSmall,@strSharhKoli,@day,@month,@year,'amani',@fldCodeVasete,@fldShomareSanad output 

										execute CodeKolHesab'tarafeentezami' ,@CodeMoin output
										set @CodeKolkham =substring(@CodeMoin, 1, @TooleKol)
										set @CodeMoinKham =substring(@CodeMoin,@TooleKol+1,@Toolemoin)
										execute InsertSanadLast  @CodeKolkham,@CodeMoinKham,@CodeMoin,NULL,NULL,@decMablaghKolFactor,0,1,@dateSmall,@strSharhKoli,@day,@month,@year,'amani',@fldCodeVasete,@fldShomareSanad

									  INSERT INTO [dbo].[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]
										   ,[fldShomareBargashtAmani]
										   ,[fldDateEngheza])
											SELECT
											@fldShomareSanad
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]	
										   ,@fldCodeAshkhas_in								   
										   ,[fldCodeUser]
										   ,[fldRadif]		
										   ,[fldCodeAnbar]						   
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]										   
										   ,@fldShomareAmani 
										   ,[fldDateEngheza]
										   output from @dtForoosh


									--ثبت انبار وارده ریز خرید
									   INSERT INTO [dbo].[tblRizeBargashtAzKharid]
												(
												--[fldCodeTafsili]
												--,[fldCodeUser]
												--,[fldRadif]
												--,[fldCodeAnbar]
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,[fldShomareAmani]
											[fldShomareSanad]
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,[fldCodeTafsili]
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,[fldCodeAnbar]
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,[fldShomareBargashtAmani]
										   ,[fldDateEngheza])
												select
												--@fldCodeAshkhas_in
												--,[fldCodeUser]
												--,[fldRadif]
												--,@fldCodeAnbar_in
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,@fldShomareAmani
											@fldShomareSanad
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,@fldCodeAshkhas_in
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,@fldCodeAnbar_out
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,@fldShomareAmani 
										   ,[fldDateEngheza]
												output from @dtKharid;
											
											--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 @strResult='insertOk'

										end --flag insert
									end --count rowShomare Amani

							--set @lngCountAmani=(Select Count(fldShomareAmani) from tblRizeForoosh Where fldShomareAmani=@fldShomareAmani)
							if ( @lngCountAmani > 0)
									begin
										if @InsertType='arshive'
										  begin

											set @fldShomareSanad=(Select top(1) fldShomareSanad from tblRizeBargashtAzForoosh where fldShomareBargashtAmani=@fldShomareAmani and fldType='bargashtamani')
											delete from tblRizeBargashtAzForoosh where fldShomareBargashtAmani=@fldShomareAmani and fldType='bargashtamani'
											delete from tblRizeBargashtAzKharid where fldShomareBargashtAmani=@fldShomareAmani and fldType='bargashtamani'
											delete from tblSodooreSanad where @fldShomareSanad=@fldShomareSanad and fldType='bargashtamani'

											--INSERT       INTO              tblTest7(fld1, fld2, fld3)
											--			VALUES        ('1',1,1)

											execute  ToolePaye 'kol',@TooleKol output
											execute  ToolePaye 'moin',@Toolemoin output
											execute codemoinhesab 'forooshamani' ,@CodeMoin output
											set @CodeKolkham =substring(@CodeMoin, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoin,@TooleKol+1,@Toolemoin)											
											
											set @Date=(Select Top(1) fldDate  from @dtForoosh)
											set @year=substring(convert(nvarchar(20),@Date),1,4)
											
											set @month=substring(convert(nvarchar(20),@Date),5,2)
											set @day=substring(convert(nvarchar(20),@Date),7,2)
											set @dateSmall=substring(convert(nvarchar(15),@Date),1,8)


											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoin,@fldCodeAshkhas_in,'1',0,@decMablaghKolFactor,2,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtamani',@fldCodeVasete,@fldShomareSanad 

											execute CodeKolHesab'tarafeentezami' ,@CodeMoin output
											set @CodeKolkham =substring(@CodeMoin, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoin,@TooleKol+1,@Toolemoin)
											execute InsertSanadLast  @CodeKolkham,@CodeMoinKham,@CodeMoin,NULL,NULL,@decMablaghKolFactor,0,1,@dateSmall,@strSharhKoli,@day,@month,@year,'bargashtamani',@fldCodeVasete,@fldShomareSanad

										INSERT INTO [dbo].[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]
												,[fldShomareBargashtAmani]
												,[fldDateEngheza])
												SELECT
												@fldShomareSanad
												,[fldShomareFactor]
												,[fldCodeVasete]												
												,@fldCodeAshkhas_in
												,[fldCodeUser]
												,[fldRadif]		
												,[fldCodeAnbar]
												,[fldCodeKala]
												,[fldSharhKala]
												,[fldTedadCarton]
												,[fldTedadJoz]
												,[fldFeeJoz]
												,[fldFeeYekCarton]
												,[fldFeeKol]
												,[fldDarsadTakhfif]
												,[fldMablaghTakhfif]
												,[fldFeeVahed1BadAzTakhfif]
												,[fldFeeVahed2BadAzTakhfif]
												,[fldArzeshAfzode]
												,[fldFeeKolBadAzTakhfif]
												,[fldMablaghKhales]
												,[fldType]
												,[fldDate]
												,[fldTime]
												,@fldShomareAmani 
												,[fldDateEngheza]
												output from @dtForoosh


								--ثبت انبار وارده ریز خرید
												INSERT INTO [dbo].[tblRizeBargashtAzKharid]
															(
												--[fldCodeTafsili]
												--,[fldCodeUser]
												--,[fldRadif]
												--,[fldCodeAnbar]
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,[fldShomareAmani]
											[fldShomareSanad]
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,[fldCodeTafsili]
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,[fldCodeAnbar]
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,[fldShomareBargashtAmani]
										   ,[fldDateEngheza])
												select
												--@fldCodeAshkhas_in
												--,[fldCodeUser]
												--,[fldRadif]
												--,@fldCodeAnbar_in
												--,[fldCodeKala]
												--,[fldSharhKala]
												--,[fldTedadJoz]
												--,[fldType]
												--,[fldDate]
												--,[fldTime]
												--,@fldShomareAmani
											@fldShomareSanad
										   ,[fldShomareFactor]
										   ,[fldCodeVasete]
										   ,@fldCodeAshkhas_in
										   ,[fldCodeUser]
										   ,[fldRadif]
										   ,@fldCodeAnbar_out
										   ,[fldCodeKala]
										   ,[fldSharhKala]
										   ,[fldTedadCarton]
										   ,[fldTedadJoz]
										   ,[fldFeeJoz]
										   ,[fldFeeYekCarton]
										   ,[fldFeeKol]
										   ,[fldDarsadTakhfif]
										   ,[fldMablaghTakhfif]
										   ,[fldFeeVahed1BadAzTakhfif]
										   ,[fldFeeVahed2BadAzTakhfif]
										   ,[fldArzeshAfzode]
										   ,[fldFeeKolBadAzTakhfif]
										   ,[fldMablaghKhales]
										   ,[fldType]
										   ,[fldDate]
										   ,[fldTime]
										   ,@fldShomareAmani 
										   ,[fldDateEngheza]
												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
			else
				set @strResult='mmm'
		   end catch
   
		END
GO

-- ===============================================
-- SP: [dbo].[InsertInfoBargashtAzForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoBargashtAzForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoBargashtAzForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

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



	@lngMablaghNaghdPardakht bigint,
	@lngMablaghBankPardakht bigint,
	@lngMablaghTakhfifPardakht bigint,
	@karmozd decimal,

	@dtForoosh tpRizeBargashAzForoosh2  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),



@ShomarePishfactor bigint,



	@strResult nvarchar(25) output,
	@strResult2 nvarchar(25) output,
	@flagInsert nvarchar(10)
	--@ErrorLine bigint output
	
AS
create table #tmpColor (
	MoinKamel nvarchar(50) COLLATE Persian_100_CI_AS,
	fldColorBank int,
	fldColorSandoogh int , 
	fldColorSooratHesab int

)
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,@CodeMoinKarmozd nvarchar(10),@Sharh nvarchar(100)
			declare @CodeMoinHoghoogh nvarchar(10),@SharhePoorsant nvarchar(100), @SharheArzesheAfzoode nvarchar(100)
			--set @year=substring(convert(nvarchar(20),@fldDate),3,2)
			set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
			set @year=@yearFull
			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)
			set @dateSmall=@fldDate
			declare @lngSumDaryaft bigint
			set @intRadif=0


			set @SharhePoorsant='معکوس پورسانت برگشت ' + Convert(varchar,@fldShomareFactor)
		
			if @fldSharhFactor=''
					set @fldSharhFactor='none'

			set @SharheArzesheAfzoode=' برگشت از فروش ' +  Convert(varchar,@fldShomareFactor)  + ' ' + @fldSharhfactor

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

					delete from tblBargashtAzForoosh
						where fldShomareSanad=@fldShomareSanad

					insert into #tmpColor
								(MoinKamel,fldColorBank ,fldColorSandoogh , fldColorSooratHesab )
								Select fldMoinKamel,fldColorBank,fldColorSandoogh,fldColorSooratHesab from tblSodooreSanad Where fldSanad=@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,fldVaziat=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,@SharheArzesheAfzoode,@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  , fldVaziat='forooshecheck' 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,'0',0,@lngMablaghPorsant,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',@lngMablaghPorsant,0,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@SharhePoorsant,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
										end 
									
								end 
								--پایان سند پورسانت واسطه ها و ویزیتور ها 


								--کارمزد بانک
									if @karmozd>0
										begin			
											declare @tmp nvarchar(20)
											set @intRadif=@intRadif+1
									
											execute codemoinhesab 'karmozd' ,@CodeMoinKarmozd output

									
											--set @CodeMoinKarmozd='61226'

											set @CodeKolkham =substring(@CodeMoinKarmozd, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinKarmozd,@TooleKol+1,@Toolemoin)
											set @Sharh='کارمزد بانک ' + Convert(varchar,@ShomarePardakht)

											set @tmp=@CodeKolBank + @CodeMoinBank

											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinKarmozd,NULL,'0',@karmozd,0,@intRadif,@fldDate,@Sharh,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
											set @intRadif=@intRadif+1
											execute InsertSanadLast @CodeKolBank,@CodeMoinBank,@tmp,NUll,NULL,0,@karmozd,@intRadif,@fldDate,@Sharh,@day,@month,@year,'bargashtazforoosh','',@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,'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]
							   ,[fldShomarePishfactor]
							   )
								 values(@fldShomareFactor,@fldShomareSanad,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end ,@ShomarePishfactor)

							 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]
						   ,[fldDateEngheza]
						   ,[fldDateSakht]
						   ,[fldbatchNumber]
						   ,[fldGhymatMasrafkonande])
							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]
						   ,[fldDateEngheza]
						   ,[fldDateSakht]
						   ,[fldbatchNumber]
						   ,[fldGhymatMasrafkonande] 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' ,@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,@SharheArzesheAfzoode,@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  , fldVaziat='forooshecheck' 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,'0',0,@lngMablaghPorsant,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',@lngMablaghPorsant,0,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@SharhePoorsant,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
										end 
									
								end 

							--کارمزد بانک
								if @karmozd>0
									begin									
										set @intRadif=@intRadif+1
									
										execute codemoinhesab 'karmozd' ,@CodeMoinKarmozd output

									
										--set @CodeMoinKarmozd='61226'

										set @CodeKolkham =substring(@CodeMoinKarmozd, 1, @TooleKol)
										set @CodeMoinKham =substring(@CodeMoinKarmozd,@TooleKol+1,@Toolemoin)
										set @Sharh='کارمزد بانک ' + Convert(varchar,@ShomarePardakht)
										set @tmp=@CodeKolBank + @CodeMoinBank

										execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinKarmozd,NULL,'0',@karmozd,0,@intRadif,@fldDate,@Sharh,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
										set @intRadif=@intRadif+1
										execute InsertSanadLast @CodeKolBank,@CodeMoinBank,@tmp,NUll,NULL,0,@karmozd,@intRadif,@fldDate,@Sharh,@day,@month,@year,'bargashtazforoosh','',@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  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]
							   ,[fldShomarePishfactor]
							   )
								 values(@maxFactor,@fldShomareSanad,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end,@ShomarePishfactor )

							 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]
						   ,[fldDateEngheza]
						   ,[fldDateSakht]
						   ,[fldbatchNumber]
						   ,[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]
						   ,[fldDateEngheza]
						   ,[fldDateSakht]
						   ,[fldbatchNumber]
						   ,[fldGhymatMasrafkonande] 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,@SharheArzesheAfzoode,@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  , fldVaziat='forooshecheck' 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,'0',0,@lngMablaghPorsant,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',@lngMablaghPorsant,0,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@SharhePoorsant,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
										end 
									
								end 
								--پایان سند پورسانت واسطه ها و ویزیتور ها 

															--کارمزد بانک
								if @karmozd>0
									begin									
										set @intRadif=@intRadif+1
									
										execute codemoinhesab 'karmozd' ,@CodeMoinKarmozd output

									
										--set @CodeMoinKarmozd='61226'

										set @CodeKolkham =substring(@CodeMoinKarmozd, 1, @TooleKol)
										set @CodeMoinKham =substring(@CodeMoinKarmozd,@TooleKol+1,@Toolemoin)
										set @Sharh='کارمزد بانک ' + Convert(varchar,@ShomarePardakht)
										set @tmp=@CodeKolBank + @CodeMoinBank

										execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinKarmozd,NULL,'0',@karmozd,0,@intRadif,@fldDate,@Sharh,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad
										set @intRadif=@intRadif+1
										execute InsertSanadLast @CodeKolBank,@CodeMoinBank,@tmp,NUll,NULL,0,@karmozd,@intRadif,@fldDate,@Sharh,@day,@month,@year,'bargashtazforoosh','',@fldShomareSanad	
													
									
									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]
							   ,[fldShomarePishfactor]
							   )
								 values(@fldShomareFactor,@fldShomareSanad,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end ,@ShomarePishfactor)--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]
													   ,[fldDateEngheza]
													   ,[fldDateSakht]
													   ,[fldbatchNumber]
													   ,[fldGhymatMasrafkonande])
														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]
													   ,[fldDateEngheza]
													   ,[fldDateSakht]
													   ,[fldbatchNumber]
													   ,[fldGhymatMasrafkonande] 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 )
			update tblSodooreSanad set fldColorBank=#tmpColor.fldColorBank,fldColorSandoogh=#tmpColor.fldColorSandoogh,fldColorSooratHesab=#tmpColor.fldColorSooratHesab from #tmpColor Where tblSodooreSanad.fldSanad=@fldShomareSanad and fldMoinKamel=#tmpColor.MoinKamel

			 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

-- ===============================================
-- SP: [dbo].[InsertInfoBargashtAzForooshTest]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoBargashtAzForooshTest', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoBargashtAzForooshTest] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[InsertInfoBargashtAzKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoBargashtAzKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoBargashtAzKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
Alter PROCEDURE [dbo].[InsertInfoBargashtAzKharid]
@flagKharid nvarchar(10),

@dtCheckDaryafti tblCheckDaryafti2 readonly,
@intHasRowCheckDaryafti int,
@lngMablaghKolCheckHa bigint,
@lngMablaghNaghdDaryaft bigint,
@lngMablaghBankDaryaft bigint,
@lngMablaghBankDaryaft2 bigint,
@lngMablaghBankDaryaft3 bigint,
@lngMablaghTakhfifDaryaft bigint,


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


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

@lngCodeSandoghDaryaft bigint,
@lngCodeBankDaryaft bigint,
@lngCodeBankDaryaft2 bigint,
@lngCodeBankDaryaft3 bigint,

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

@strResult nvarchar(25) output,
@strResult2 NVarChar (25) output,
@flagInsert nvarchar(10)
AS
create table #tmpColor (
	MoinKamel nvarchar(50) COLLATE Persian_100_CI_AS,
	fldColorBank int,
	fldColorSandoogh int , 
	fldColorSooratHesab int
)

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, @SharheArzesheAfzoode nvarchar(100)
					--,@ShomarePardakht bigint,@lngSumPardakht bigint
					--set @year=substring(convert(nvarchar(20),@fldDate),3,2)
					set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
					set @year=@yearFull
					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)
					set @dateSmall=@fldDate
					declare @maxFactor bigint
					set @intRadif=0
					set @fldCodeVasete=0
					----------End Declare and set Init Values----------
			set @SharheArzesheAfzoode='  برگشت از خرید ' +  Convert(varchar,@fldShomareFactor) + ' ' + @fldSharhfactor
			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

					insert into #tmpColor
								(MoinKamel,fldColorBank ,fldColorSandoogh , fldColorSooratHesab )
								Select fldMoinKamel,fldColorBank,fldColorSandoogh,fldColorSooratHesab from tblSodooreSanad Where fldSanad=@fldShomareSanad
					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,@SharheArzesheAfzoode,@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 (@strSharhBank2 is null or @strSharhBank2='')
				begin
					set @strSharhBank2='noneDaryaft'
				end
				if (@strSharhBank3 is null or @strSharhBank3='')
				begin
					set @strSharhBank3='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+@lngMablaghBankDaryaft2+@lngMablaghBankDaryaft3+@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 @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 @lngMablaghBankDaryaft2>0
					begin
						set @intRadif=@intRadif+1
						set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft2
						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,@lngMablaghBankDaryaft2,0,@intRadif,@dateSmall,@strSharhBank2,@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 @lngMablaghBankDaryaft3>0
					begin
						set @intRadif=@intRadif+1
						set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft3
						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,@lngMablaghBankDaryaft3,0,@intRadif,@dateSmall,@strSharhBank3,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad						
					end  
				--سند بانک
				if @lngMablaghBankDaryaft3>0
					begin
						set @intRadif=@intRadif+1
						set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft3
						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,@lngMablaghBankDaryaft3,0,@intRadif,@dateSmall,@strSharhBank3,@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+@lngMablaghBankDaryaft2+@lngMablaghBankDaryaft3+@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],[fldDateEngheza],[fldDateSakht],[fldBatchNumber])
					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],[fldDateEngheza],[fldDateSakht],[fldBatchNumber]
					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 output

									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,@SharheArzesheAfzoode,@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 (@strSharhBank2 is null or @strSharhBank2='')
									begin
										set @strSharhBank2='noneDaryaft'
									end
									if (@strSharhBank3 is null or @strSharhBank3='')
									begin
										set @strSharhBank3='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+@lngMablaghBankDaryaft2+@lngMablaghBankDaryaft3+@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 @lngMablaghBankDaryaft2>0
										begin
											set @intRadif=@intRadif+1
											set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft2
											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,@lngMablaghBankDaryaft2,0,@intRadif,@dateSmall,@strSharhBank2,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
										end
									if @lngMablaghBankDaryaft3>0
										begin
											set @intRadif=@intRadif+1
											set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft3
											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,@lngMablaghBankDaryaft3,0,@intRadif,@dateSmall,@strSharhBank3,@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],[fldDateEngheza],[fldDateSakht],[fldBatchNumber])
									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],[fldDateEngheza],[fldDateSakht],[fldBatchNumber]
									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 output

									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,@SharheArzesheAfzoode,@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 (@strSharhBank2 is null or @strSharhBank2='')
										begin
											set @strSharhBank2='noneDaryaft'
										end
									if (@strSharhBank3 is null or @strSharhBank3='')
										begin
											set @strSharhBank3='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+@lngMablaghBankDaryaft2+@lngMablaghBankDaryaft3+@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 @lngMablaghBankDaryaft2>0
										begin											
											set @intRadif=@intRadif+1
											set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft2
											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,@lngMablaghBankDaryaft2,0,@intRadif,@dateSmall,@strSharhBank2,@day,@month,@year,'bargashtazkharid',@fldCodeVasete,@fldShomareSanad
										end
									--سند بانک
									if @lngMablaghBankDaryaft3>0
										begin											
											set @intRadif=@intRadif+1
											set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft3
											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,@lngMablaghBankDaryaft3,0,@intRadif,@dateSmall,@strSharhBank2,@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],[fldDateEngheza],[fldDateSakht],[fldBatchNumber])
									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],[fldDateEngheza],[fldDateSakht],[fldBatchNumber]
									output from @dtKharid;
									set @strResult=convert(nvarchar(17),@maxFactor)
									set @strResult2='insert'
									set @flagInsert='yes_byNo'
						end
			

			end--aaaa


			update tblSodooreSanad set fldColorBank=#tmpColor.fldColorBank,fldColorSandoogh=#tmpColor.fldColorSandoogh,fldColorSooratHesab=#tmpColor.fldColorSooratHesab from #tmpColor Where tblSodooreSanad.fldSanad=@fldShomareSanad and fldMoinKamel=#tmpColor.MoinKamel

			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

-- ===============================================
-- SP: [dbo].[InsertInfoEnteghal]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoEnteghal', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoEnteghal] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[InsertInfoEnteghal]
	@dtForoosh tpRizeForoosh_EnteghalNew readonly,
	@dtKharid tpRizeKharid_EnteghalNew 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

-- ===============================================
-- SP: [dbo].[InsertInfoForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[InsertInfoForoosh]
	@typeNetwork nvarchar(10),
	@flagForoosh nvarchar(10),
	@MultiFee bigint,
	@fldCodeTafsili bigint,

	@fldCodeVasete nvarchar(10),
	@fldCodeVasete2 nvarchar(10),
	@lngMablaghPorsant bigint,

	@fldCodeSuperVizor nvarchar(10),
	@lngMablaghPorsantSuperVizor bigint,

    @fldShomareFactor bigint,
    @fldShomareSanad bigint,
    @fldDate bigint,
	@fldSharhFactor nvarchar(250),
	@dtForoosh tpRizeForoosh11  readonly,
	@dtCheckDaryafti tblCheckDaryaftiNewer4 readonly,
	@lngHazineHamlVaNaghl bigint,
	@lngArzeshAfzode bigint,
	@lngMablaghKolFactor [decimal](18, 2),
	@lngMablaghKolCheckHa [decimal](18, 2),
	@intHasRowCheckDaryafti int,
	@lngMablaghNaghdDaryaft [decimal](18, 2),
    @lngMablaghBankDaryaft [decimal](18, 2),
	@lngMablaghBankDaryaft2 [decimal](18, 2),
	@lngMablaghBankDaryaft3 [decimal](18, 2),
	@lngMablaghTakhfifDaryaft [decimal](18, 2),
	@lngCodeSandoghDaryaft bigint,
	@lngCodeBankDaryaft bigint,
	@lngCodeBankDaryaft2 bigint,
	@lngCodeBankDaryaft3 bigint,
	@ShomarePeigiri nvarchar(50),
	@ShomarePeigiri2 nvarchar(50),
	@ShomarePeigiri3 nvarchar(50),
	--شرح دریافت
	@strSharhNaghd nvarchar(50), 
	@strSharhBank nvarchar(50),
	@strSharhBank2 nvarchar(50),
	@strSharhBank3 nvarchar(50),

	@strSharhCheck nvarchar(50),
	@strSharhTakhfif nvarchar(50),
	@strSharhKoli nvarchar(50),

	@ShomarepishFactor bigint,

	@strResult nvarchar(25) output,
	@strResult2 nvarchar(25) output,
	@flagInsert nvarchar(10)
AS

create table #tmpColor (
	MoinKamel nvarchar(50) COLLATE Persian_100_CI_AS,
	fldColorBank int,
	fldColorSandoogh int , 
	fldColorSooratHesab int

)

BEGIN

	begin transaction AddRecord
		begin try
			declare @intRadif int,@CodeMoinHesabhayeDaryaftani nvarchar(100),@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@TooleKol bigint,@Toolemoin bigint, @lngsum [decimal](18, 2)
			declare @day nvarchar(4),@Month nvarchar(4),@year nvarchar(5),@ShomareDaryaft bigint,@yearFull nvarchar(5),@dateSmall bigint
			declare @CodeMoinHoghoogh nvarchar(10),@CodeMoinHesabhayePardakhtani nvarchar(10), @SharhePoorsant nvarchar(50),@NoeTafzili  nvarchar(1),@MoinDaryaftiPersonel nvarchar(10),@KolMoinDaryaftiPersonel nvarchar(10), @SharheArzesheAfzoode nvarchar(100),@SharheAutoFactor nvarchar(100)

			--set @year=substring(convert(nvarchar(20),@fldDate),3,2)
			set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
			set @year=@yearFull
			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)
			set @dateSmall=@fldDate
			declare @lngSumDaryaft bigint
			set @intRadif=0

			set @NoeTafzili =(Select fldCodeNoe from tblTafzili where fldCodeTafzili=@fldCodeTafsili)
			set @MoinDaryaftiPersonel='99'
			set @KolMoinDaryaftiPersonel='11399'
		
			if @fldSharhFactor=''
					set @fldSharhFactor='none'


					--######برای اصلاح سند حسابداری مریوط به پورانتهاییه که اشتباها کدنوعشون 1 بوده
					UPDATE       tblSodooreSanad
					SET                fldCodeNoeTafzili = '0'
					WHERE        (fldMoinKamel = '31303') and fldCodeNoeTafzili='1'

					UPDATE       tblSodooreSanad
					SET                fldCodeNoeTafzili = '0'
					WHERE        (fldMoinKamel = '11301') and fldCodeNoeTafzili='1'


					UPDATE       tblSodooreSanad
					SET                fldCodeNoeTafzili = '0'
					WHERE        (fldMoinKamel = '71301') and fldCodeNoeTafzili='1'
					--####################################
			set @SharhePoorsant='پورسانت فاکتور' + Convert(varchar,@fldShomareFactor)
			
			set @SharheArzesheAfzoode='شماره فاکتور ' +  Convert(varchar,@fldShomareFactor)   + ' ' + @fldSharhfactor
			set @SharheAutoFactor ='شماره فاکتور ' +  Convert(varchar,@fldShomareFactor)  

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

					delete from tblForoosh
						where fldShomareSanad=@fldShomareSanad

					insert into #tmpColor
								(MoinKamel,fldColorBank ,fldColorSandoogh , fldColorSooratHesab )
								Select fldMoinKamel,fldColorBank,fldColorSandoogh,fldColorSooratHesab from tblSodooreSanad Where fldSanad=@fldShomareSanad

					delete from tblSodooreSanad
						where fldSanad=@fldShomareSanad

					set @ShomareDaryaft=(Select fldShomareDaryaft from tblDaryaft Where fldShomareSanad= @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)
							--چون در حالت ویرایش میباشد از لست استفاده کردم
							
							if @NoeTafzili='1'
								execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,@SharheAutoFactor,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
							else
								execute InsertSanadLast @CodeKolkham,@MoinDaryaftiPersonel,@KolMoinDaryaftiPersonel,@fldCodeTafsili,'0',@lngMablaghKolFactor,0,@intRadif,@dateSmall,@SharheAutoFactor,@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,@SharheAutoFactor,@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,@SharheArzesheAfzoode ,@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 (@strSharhBank2 is null or @strSharhBank2='')
								begin
									set @strSharhBank2='noneDaryaft'
								end 					
							if (@strSharhBank3 is null or @strSharhBank3='')
								begin
									set @strSharhBank3='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									
									
									
									
									if isnumeric(@ShomarePeigiri)=1 
										update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri where fldMoinKamel= @CodeMoinHesabhayeDaryaftani And fldSanad=@fldShomareSanad
								end 
							if @lngMablaghBankDaryaft2>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft2
									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,@lngMablaghBankDaryaft2,0,@intRadif,@dateSmall,@strSharhBank2,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad									
									
									
									
									if isnumeric(@ShomarePeigiri)=1 
										update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri2 where fldMoinKamel= @CodeMoinHesabhayeDaryaftani And fldSanad=@fldShomareSanad
								end 
								
							if @lngMablaghBankDaryaft3>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft3
									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,@lngMablaghBankDaryaft3,0,@intRadif,@dateSmall,@strSharhBank3,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad									
									
									
									
									if isnumeric(@ShomarePeigiri)=1 
										update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri3 where fldMoinKamel= @CodeMoinHesabhayeDaryaftani And fldSanad=@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+@lngMablaghBankDaryaft2+@lngMablaghBankDaryaft3+@lngMablaghNaghdDaryaft+@lngMablaghKolCheckHa)
							if(@lngSumDaryaft>0)
							begin
								set @intRadif=@intRadif+1
								
								if @NoeTafzili='1'
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad 
								else
									execute InsertSanadLast @CodeKolkham,@MoinDaryaftiPersonel,@KolMoinDaryaftiPersonel,@fldCodeTafsili,'0',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,'0',@lngMablaghPorsant,0,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',0,@lngMablaghPorsant,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@SharhePoorsant,@day,@month,@year,'foroosh','',@fldShomareSanad
										end 
									
								end 

							

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

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

									--ثبت ریز اطلاعات چک	
									Insert into  tblCheckeDaryafti (fldShomareCheck,fldSayad,fldShaba,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldSharheDaryaft,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
											Select fldShomareCheck,fldSayad,fldShaba,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldSharheDaryaft,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]
							   ,[fldShomarepishFactor]
							   ,[fldCodeFeeDynamic]
							   
							   )
								 values(@fldShomareFactor,@fldShomareSanad,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end ,@ShomarepishFactor,@MultiFee)
								 
							 INSERT INTO tblRizeForoosh
						   ([fldShomareSanad]
						   ,[fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeVasete2]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldDarsadArzeshAfzoode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime]
						   ,[fldEshantion]
						   ,[fldDateEngheza]
						   ,[fldDateSakht]
						   ,[fldBatchNumber]
						   ,[fldGhymatMasrafkonande]
						   ,[fldCodeMasterEshantion])
							select @fldShomareSanad
						   ,@fldShomareFactor
						   ,[fldCodeVasete]
						   ,[fldCodeVasete2]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldDarsadArzeshAfzoode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime]
						   ,[fldEshantion]
						   ,[fldDateEngheza]
						   ,[fldDateSakht]
						   ,[fldBatchNumber]
						   ,[fldGhymatMasrafkonande]
						   ,[fldCodeMasterEshantion] 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
						--کاربر دیگری در همین لحظه شماره فاکتور را گرفت
							if @typeNetwork='yes'
								begin
									set @fldShomareFactor=@maxFactor
									set @resultExist = 0 
								end
							else
								begin
									set @strResult=convert(nvarchar(17),@maxFactor)
									set @strResult2='New_Enter'
									rollback transaction AddRecord;
									return
								end
							--در قسمت ویندوزی به کاربر کادری را نشان دهد که max+1 می باشد
							--yes
								--insert
							--no
								--inputbox در برنامه ویندوز که کاربر خودش شماره فاکتور را مشخص کند
								--باید اینجا چکار کنم؟؟؟؟
						end 
					--ehsan added
					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)

							if @NoeTafzili='1'
								execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad output 
							else
								execute InsertSanadFirst @CodeKolkham,@MoinDaryaftiPersonel,@KolMoinDaryaftiPersonel,@fldCodeTafsili,'0',@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,@SharheAutoFactor,@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,@SharheArzesheAfzoode,@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 (@strSharhBank2 is null or @strSharhBank2='')
								begin
									set @strSharhBank2='noneDaryaft'
								end
							if (@strSharhBank3 is null or @strSharhBank3='')
								begin
									set @strSharhBank3='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

									
									if isnumeric(@ShomarePeigiri)=1 
										update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri where fldMoinKamel= @CodeMoinHesabhayeDaryaftani And fldSanad=@fldShomareSanad
								end 
							if @lngMablaghBankDaryaft2>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft2
									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,@lngMablaghBankDaryaft2,0,@intRadif,@dateSmall,@strSharhBank2,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad

									
									if isnumeric(@ShomarePeigiri2)=1 
										update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri2 where fldMoinKamel= @CodeMoinHesabhayeDaryaftani And fldSanad=@fldShomareSanad
								end 
							
							if @lngMablaghBankDaryaft3>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft3
									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,@lngMablaghBankDaryaft3,0,@intRadif,@dateSmall,@strSharhBank3,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad

									
									if isnumeric(@ShomarePeigiri2)=1 
										update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri2 where fldMoinKamel= @CodeMoinHesabhayeDaryaftani And fldSanad=@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+@lngMablaghBankDaryaft2+@lngMablaghBankDaryaft3+@lngMablaghNaghdDaryaft+@lngMablaghKolCheckHa)
							if @lngSumDaryaft>0
							begin
								set @intRadif=@intRadif+1
								if @NoeTafzili='1'
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,'none',@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad 
								else
									execute InsertSanadLast @CodeKolkham,@MoinDaryaftiPersonel,@KolMoinDaryaftiPersonel,@fldCodeTafsili,'0',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,'0',@lngMablaghPorsant,0,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',0,@lngMablaghPorsant,@intRadif,@dateSmall,@SharhePoorsant,@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)

											declare @SharhePoorsant2 nvarchar(50)
											set @SharhePoorsant2='پورسانت فاکتور' + Convert(varchar,@fldShomareFactor)
												
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'0',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@SharhePoorsant,@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,fldSayad,fldShaba,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldSharheDaryaft,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
											Select fldShomareCheck,fldSayad,fldShaba,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldSharheDaryaft,fldMablagh,@fldCodeTafsili,@fldDate,@ShomareDaryaft,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
								end
							INSERT INTO tblForoosh
							   ([fldShomareFactorForoosh]
							   ,[fldShomareSanad]
							   ,[fldDate]
							   ,[fldSharhFactor]
							   ,[fldShomarepishFactor]
							   ,[fldCodeFeeDynamic]
							   
							   )
								 values(@maxFactor,@fldShomareSanad,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end,@ShomarepishFactor,@MultiFee )

							 INSERT INTO tblRizeForoosh
						   ([fldShomareSanad]
						   ,[fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeVasete2]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldDarsadArzeshAfzoode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime]
						   ,[fldEshantion]
						   ,[fldDateEngheza]
						   ,[fldDateSakht]
						   ,[fldBatchNumber]
						   ,[fldGhymatMasrafkonande]
						   ,[fldCodeMasterEshantion])
							select @fldShomareSanad
						   ,@maxFactor
						   ,[fldCodeVasete]
						   ,[fldCodeVasete2]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldDarsadArzeshAfzoode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime]
						   ,[fldEshantion]
						   ,[fldDateEngheza]
						   ,[fldDateSakht]
						   ,[fldBatchNumber]
						   ,[fldGhymatMasrafkonande]
						   ,[fldCodeMasterEshantion] 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)

							if @NoeTafzili='1' 
								execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',@lngMablaghKolFactor,0,@intRadif,@dateSmall,@SharheAutoFactor,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad output 
							else
								execute InsertSanadFirst @CodeKolkham,@MoinDaryaftiPersonel,@KolMoinDaryaftiPersonel,@fldCodeTafsili,'0',@lngMablaghKolFactor,0,@intRadif,@dateSmall,@SharheAutoFactor,@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,@SharheAutoFactor,@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,@SharheArzesheAfzoode,@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 (@strSharhBank2 is null or @strSharhBank2='')
								begin
									set @strSharhBank2='noneDaryaft'
								end
							if (@strSharhBank3 is null or @strSharhBank3='')
								begin
									set @strSharhBank3='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
								
									
									if isnumeric(@ShomarePeigiri)=1 
										update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri where fldMoinKamel= @CodeMoinHesabhayeDaryaftani And fldSanad=@fldShomareSanad
								end 

							if @lngMablaghBankDaryaft2>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft2
									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,@lngMablaghBankDaryaft2,0,@intRadif,@dateSmall,@strSharhBank2,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								
									
									if isnumeric(@ShomarePeigiri2)=1 
										update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri2 where fldMoinKamel= @CodeMoinHesabhayeDaryaftani And fldSanad=@fldShomareSanad
								end 
							if @lngMablaghBankDaryaft3>0
								begin
									set @intRadif=@intRadif+1
									set @CodeMoinHesabhayeDaryaftani=@lngCodeBankDaryaft3
									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,@lngMablaghBankDaryaft3,0,@intRadif,@dateSmall,@strSharhBank3,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad
								
									
									if isnumeric(@ShomarePeigiri3)=1 
										update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri3 where fldMoinKamel= @CodeMoinHesabhayeDaryaftani And fldSanad=@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+@lngMablaghBankDaryaft2+@lngMablaghBankDaryaft3+@lngMablaghNaghdDaryaft+@lngMablaghKolCheckHa)
							if @lngSumDaryaft>0
							begin
								set @intRadif=@intRadif+1

								if @NoeTafzili='1'
									execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafsili,'1',0,@lngSumDaryaft,@intRadif,@dateSmall,@strSharhKoli,@day,@month,@year,'foroosh',@fldCodeVasete,@fldShomareSanad 
								else
									execute InsertSanadLast @CodeKolkham,@MoinDaryaftiPersonel,@KolMoinDaryaftiPersonel,@fldCodeTafsili,'0',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,@SharhePoorsant,@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,'0',0,@lngMablaghPorsant,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',@lngMablaghPorsantSuperVizor,0,@intRadif,@dateSmall,@SharhePoorsant,@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,'0',0,@lngMablaghPorsantSuperVizor,@intRadif,@dateSmall,@SharhePoorsant,@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,fldSayad,fldShaba,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldSharheDaryaft,fldMablagh,fldCodeSahebeCheck,fldDateDaryaft,fldShomareDaryaft,fldVasete,fldSanad)
											Select fldShomareCheck,fldSayad,fldShaba,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldSharheDaryaft,fldMablagh,@fldCodeTafsili,@fldDate,@ShomareDaryaft,@fldCodeVasete,@fldShomareSanad output from @dtCheckDaryafti;	
								end
							INSERT INTO tblForoosh
							   ([fldShomareFactorForoosh]
							   ,[fldShomareSanad]
							   ,[fldDate]
							   ,[fldSharhFactor]
							   ,[fldShomarepishFactor]
							   ,[fldCodeFeeDynamic]
							   
							   )
								 values(@fldShomareFactor,@fldShomareSanad,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end,@ShomarepishFactor,@MultiFee )

							 INSERT INTO tblRizeForoosh
													   ([fldShomareSanad]
													   ,[fldShomareFactor]
													   ,[fldCodeVasete]
													   ,[fldCodeVasete2]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldDarsadArzeshAfzoode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime]
													   ,[fldEshantion]
													   ,[fldDateEngheza]
													   ,[fldDateSakht]
													   ,[fldBatchNumber]
													   ,[fldGhymatMasrafkonande]
													   ,[fldCodeMasterEshantion])
														select @fldShomareSanad
														--edit
													   ,@fldShomareFactor
													   ,[fldCodeVasete]
													   ,[fldCodeVasete2]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldDarsadArzeshAfzoode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldTime]
													   ,[fldEshantion]
													   ,[fldDateEngheza]
													   ,[fldDateSakht]
													   ,[fldBatchNumber]
													   ,[fldGhymatMasrafkonande]
													   ,[fldCodeMasterEshantion] 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 )
			update tblSodooreSanad set fldColorBank=#tmpColor.fldColorBank,fldColorSandoogh=#tmpColor.fldColorSandoogh,fldColorSooratHesab=#tmpColor.fldColorSooratHesab from #tmpColor Where tblSodooreSanad.fldSanad=@fldShomareSanad and fldMoinKamel=#tmpColor.MoinKamel

			 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

-- ===============================================
-- SP: [dbo].[InsertInfoHavaleHazine]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoHavaleHazine', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoHavaleHazine] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[InsertInfoHavaleHazine]	
	@dtForoosh tpRizeForoosh9  readonly,
	@ShomareFactor bigint,
	@CodeKolBedehkar nvarchar(20),
	@CodeMoinBedehkar nvarchar(20),
	@CodeMoinKamelBedehkar nvarchar(20), 
	@CodeTafziliBedehkar nvarchar(20),
	
	@CodeKolBestankar nvarchar(20),
	@CodeMoinBestankar nvarchar(20),
	@CodeMoinKamelBestankar nvarchar(20), 
	

	@strResult nvarchar(25) output,
	@strResult2 nvarchar(25) output,
	@bigShomareHavaleSaved bigint output,
	@flagInsert nvarchar(10)
AS



BEGIN
	
	declare @MaxShomare bigint,@lngMablaghKolFactor bigint,@date int,@day nvarchar(2),@month nvarchar(2),@year nvarchar(4),@fldShomareSanad bigint,@fldShomareSanadArshive bigint,@yearFull nvarchar(10),@Sharh nvarchar(100)

	if @ShomareFactor=-1 
		begin
			set @MaxShomare=(select max(fldShomareFactor) as maxShomare from tblRizHavaleHazine)
			if @MaxShomare is NUll
				set @MaxShomare=1
			else
				set @MaxShomare=@MaxShomare+1
		end
	else
		begin
			set @MaxShomare=@ShomareFactor
			set @fldShomareSanadArshive=(select top(1) fldShomareSanad from tblRizHavaleHazine where fldShomareFactor=@MaxShomare)
			set @fldShomareSanad=@fldShomareSanadArshive
			delete tblRizHavaleHazine where fldShomareFactor=@MaxShomare
			delete tblSodooreSanad where fldSanad=@fldShomareSanad				
		end


	begin transaction AddRecord
		begin try
				
				 INSERT INTO tblRizHavaleHazine
						   ([fldShomareSanad]
						   ,[fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeVasete2]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldDarsadArzeshAfzoode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime]
						   ,[fldEshantion]
						   ,[fldDateEngheza]
						   ,[fldGhymatMasrafkonande]
						   ,[fldCodeMasterEshantion])
							select 0
						   ,@MaxShomare
						   ,[fldCodeVasete]
						   ,[fldCodeVasete2]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldDarsadArzeshAfzoode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,'havalekhorooj'
						   ,[fldDate]
						   ,[fldTime]
						   ,[fldEshantion]
						   ,[fldDateEngheza]
						   ,[fldGhymatMasrafkonande]
						   ,[fldCodeMasterEshantion] output  from @dtForoosh;

						   set @bigShomareHavaleSaved=@MaxShomare

						   --set @CodeMoin=SUBSTRING(@CodeMoinKamelBedehkar,len(@CodeKolBedehkar)+1,len(@CodeMoinKamelBedehkar)-len(@CodeKolBedehkar))

						 --  INSERT        iNTO              tblTest7( fld2)
							--VALUES        (@CodeMoin)

						   set @lngMablaghKolFactor =(select sum(fldMablaghKhales) as sumKhales from @dtForoosh)

						   set @date=(select top(1)flddate from @dtForoosh)
						   
						   set @yearFull=substring(convert(nvarchar(20),@date),0,5)
							set @year=@yearFull
							set @month=substring(convert(nvarchar(20),@date),5,2)
							set @day=substring(convert(nvarchar(20),@date),7,2)




							set @Sharh='حواله خروج کالا' + convert(varchar, @maxshomare)

							if @ShomareFactor=-1 --سند جدید
								execute InsertSanadFirst @CodeKolBedehkar,@CodeMoinBedehkar,@CodeMoinKamelBedehkar,@CodeTafziliBedehkar,'1',@lngMablaghKolFactor,0,1,@date,@Sharh,@day,@month,@year,'havalehazine','',@fldShomareSanad output 
							else--ویرایش
								execute InsertSanadLast @CodeKolBedehkar,@CodeMoinBedehkar,@CodeMoinKamelBedehkar,@CodeTafziliBedehkar,'1',@lngMablaghKolFactor,0,1,@date,@Sharh,@day,@month,@year,'havalehazine','',@fldShomareSanad			


							execute InsertSanadLast @CodeKolBestankar,@CodeMoinBestankar,@CodeMoinKamelBestankar,'','0',0,@lngMablaghKolFactor,2,@date,@Sharh,@day,@month,@year,'havalehazine','',@fldShomareSanad		
							

							--select * from tblsodooresanad where fldsanad=26
							--if @ShomareFactor=-1 --سند جدید
								update 	tblRizHavaleHazine set fldShomareSanad=@fldShomareSanad where fldShomareFactor= @MaxShomare 

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

-- ===============================================
-- SP: [dbo].[InsertInfoInDaramad]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoInDaramad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoInDaramad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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),
@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 tblCheckDaryafti2 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),

@lngCodeUser bigint,
@lngDateNow bigint,



@NoeKhata nvarchar(30) output 


--@NoeKhata int output
as
create table #tmpColor (
	MoinKamel nvarchar(50) COLLATE Persian_100_CI_AS,
	fldColorBank int,
	fldColorSandoogh int , 
	fldColorSooratHesab int

)

begin
	begin transaction transact
		begin try
			declare @MaxSanad bigint,@lngI bigint,@lngCount bigint,@strShomareSanad nvarchar(50),@lngCountDaryaft int,@IDOutPut bigint,@decJam decimal	,@strNameUser nvarchar(25),@strTime nvarchar(30)
			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 ;

			 set @strNameUser=(Select fldUser from tblSecurity Where fldCode=@lngCodeUser)

			 set @strtime=(SELECT ltrim(right(convert(varchar(25), getdate(), 100), 7)))

			 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)
							insert into #tmpColor
								(MoinKamel,fldColorBank ,fldColorSandoogh , fldColorSooratHesab )
								Select fldMoinKamel,fldColorBank,fldColorSandoogh,fldColorSooratHesab from tblSodooreSanad Where fldSanad=@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

							INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
								VALUES        (@lngCodeUser,@strNameUser,'درآمد','ویرایش',@lngDateNow,@strtime,@shomaredaryaft,@ShomareSanadArchive)

						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)


					if  @CodeTafzili=0
					begin
						set @CodeTafzili=''
						set @CodeNoeTafzili=''
					end
			
					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,'daramad',@CodeVasete,@strShomareSanad output	;
								end
							else	
								begin							
								  execute insertSanadLast @CodeKolSandoogh,@CodeMoinSandoogh,@strMoinKamel,NUll,NULL,@Naghd,0,@strRadif,@DateDaryaft,@SNaghd,@day,@month,@year,'daramad',@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,'daramad',@strShomareSanad output	;
							if @intRadif=1 
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										execute insertSanadFirst @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DateDaryaft,@SBank,@day,@month,@year,'daramad',@CodeVasete,@strShomareSanad output	;
									else
										begin
											execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DateDaryaft,@SBank,@day,@month,@year,'daramad',@CodeVasete,@ShomareSanadKarbar;
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,@Bank,0,@strRadif,@DateDaryaft,@SBank,@day,@month,@year,'daramad',@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,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,@day,@month,@year,'daramad',@CodeVasete,@strShomareSanad output;
										end
									else
										begin
											execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,@day,@month,@year,'daramad',@CodeVasete,@ShomareSanadKarbar;
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,@day,@month,@year,'daramad',@CodeVasete,@strShomareSanad;
								end
							--execute insertSanadFirst  @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,'daramad',@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,'daramad',@CodeVasete,@strShomareSanad output;
										end
									else
										begin
											execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifateDaryaft,@strMoinKamel,NUll,NULL,@Takhfif,0,@strRadif,@DateDaryaft,@STakhfif,@day,@month,@year,'daramad',@CodeVasete,@ShomareSanadKarbar;										
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKoltakhfifat,@CodeMoinTakhfifateDaryaft,@strMoinKamel,NUll,NULL,@Takhfif,0,@strRadif,@DateDaryaft,@STakhfif,@day,@month,@year,'daramad',@CodeVasete,@strShomareSanad;
								end
							--execute insertSanadFirst  @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,'daramad',@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,@CodeTafzili,@CodeNoeTafzili,0,@decjam,@strRadif,@DateDaryaft,@SharheKol,@day,@month,@year,'daramad',@CodeVasete,@strShomareSanad;
							if @InsertType<>'archive'								
								INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
									VALUES        (@lngCodeUser,@strNameUser,'درآمد','جدید',@lngDateNow,@strtime,@shomaredaryaft,@strShomareSanad)
						end
					else
						begin
							execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@CodeMoinDaramad,@CodeTafzili,@CodeNoeTafzili,0,@decjam,@strRadif,@DateDaryaft,@SharheKol,@day,@month,@year,'daramad',@CodeVasete,@ShomareSanadKarbar;
							if @InsertType<>'archive'								
								INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
									VALUES        (@lngCodeUser,@strNameUser,'درآمد','جدید',@lngDateNow,@strtime,@shomaredaryaft,@ShomareSanadKarbar)
						end
					--execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@CodeMoinDaramad,NUll,NUll,@decjam,0,@strRadif,@DateDaryaft,@SharheKol,'daramad';

					update tblSodooreSanad set fldColorBank=#tmpColor.fldColorBank,fldColorSandoogh=#tmpColor.fldColorSandoogh,fldColorSooratHesab=#tmpColor.fldColorSooratHesab from #tmpColor Where tblSodooreSanad.fldSanad=@ShomareSanadArchive and fldMoinKamel=#tmpColor.MoinKamel
					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,'daramad'
			--	FROM            tblSodooreSanad AS tblSodooreSanad_1

	
			--set @IDOutPut=@@IDENTITY;	

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



                         
	

	
	

end
GO

-- ===============================================
-- SP: [dbo].[InsertInfoInDaryaft]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoInDaryaft', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoInDaryaft] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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),
@ShomarePeigiri nvarchar(50),

--'پارامترهای بانک2
@CodeMoinBank2 nvarchar(10),
@Bank2 decimal,
@SBank2 nvarchar(200),
@ShomarePeigiri2 nvarchar(50),

--'پارامترهای بانک3
@CodeMoinBank3 nvarchar(10),
@Bank3 decimal,
@SBank3 nvarchar(200),
@ShomarePeigiri3 nvarchar(50),


--'پارامترهای چک
@tblCheck tblCheckDaryaftiNewer4 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,

@lngCodeUser bigint,
@lngDateNow bigint,

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

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

@NoeKhata nvarchar(30) output 


--@NoeKhata int output
as

create table #tmpColor (
	MoinKamel nvarchar(50) COLLATE Persian_100_CI_AS,
	fldColorBank int,
	fldColorSandoogh int , 
	fldColorSooratHesab int

)




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

			 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+@bank2+@bank3 +@MablaghCheck+ @Takhfif ;

			 set @SharhePoorsant='پورسانت دریافت ' + Convert(varchar,@ShomareDaryaft)

			 set @strNameUser=(Select fldUser from tblSecurity Where fldCode=@lngCodeUser)

			 set @strtime=(SELECT ltrim(right(convert(varchar(25), getdate(), 100), 7)))

			 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)
							insert into #tmpColor
								(MoinKamel,fldColorBank ,fldColorSandoogh , fldColorSooratHesab )
								Select fldMoinKamel,fldColorBank,fldColorSandoogh,fldColorSooratHesab from tblSodooreSanad Where fldSanad=@ShomareSanadArchive

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

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

							delete from tblDaryaft where fldShomareSanad=@ShomareSanadArchive
							if @ShomareDaryaft>0 
								delete from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft
							set @noekhata='update_archive'

							
							
							--set @noekhata=3


							INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
								VALUES        (@lngCodeUser,@strNameUser,'دریافت','ویرایش',@lngDateNow,@strtime,@shomaredaryaft,@ShomareSanadArchive)

						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,@CodeMoinSandoogh,@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
								if isnumeric(@ShomarePeigiri)=1 
									update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri where fldMoinKamel= @strMoinKamel And fldSanad=@strShomareSanad
						end

						--سند بانک2
					if @Bank2>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinBank2,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolBank + @CodeMoinBank2
					
							if @intRadif=1 
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										execute insertSanadFirst @CodeKolBank,@CodeMoinBank2,@strMoinKamel,NUll,NULL,@Bank2,0,@strRadif,@DateDaryaft,@SBank2,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad output	;
									else
										begin
											execute insertSanadLast @CodeKolBank,@CodeMoinBank2,@strMoinKamel,NUll,NULL,@Bank2,0,@strRadif,@DateDaryaft,@SBank2,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKolBank,@CodeMoinBank2,@strMoinKamel,NUll,NULL,@Bank2,0,@strRadif,@DateDaryaft,@SBank2,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
								end
								if isnumeric(@ShomarePeigiri)=1 
									update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri2 where fldMoinKamel= @strMoinKamel And fldSanad=@strShomareSanad
						end


					--سند بانک3
					if @Bank3>0 
						begin
							set @intRadif =@intRadif+1			
							set @strRadif=convert(nvarchar(50),@intRadif)
							set @CodeMoinKham=substring(@CodeMoinBank3,@TooleKol+1,@Toolemoin)
							set @strMoinKamel=@CodeKolBank + @CodeMoinBank3
					
							if @intRadif=1 
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										execute insertSanadFirst @CodeKolBank,@CodeMoinBank3,@strMoinKamel,NUll,NULL,@Bank3,0,@strRadif,@DateDaryaft,@SBank3,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad output	;
									else
										begin
											execute insertSanadLast @CodeKolBank,@CodeMoinBank3,@strMoinKamel,NUll,NULL,@Bank3,0,@strRadif,@DateDaryaft,@SBank3,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									execute insertSanadLast @CodeKolBank,@CodeMoinBank3,@strMoinKamel,NUll,NULL,@Bank3,0,@strRadif,@DateDaryaft,@SBank3,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad;
								end
								if isnumeric(@ShomarePeigiri)=1 
									update tblSodooreSanad set fldShomarepeigiri=@ShomarePeigiri3 where fldMoinKamel= @strMoinKamel And fldSanad=@strShomareSanad
						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,@CodeTafzili,'1',@MablaghCheck,0,@strRadif,@DateDaryaft,@SCheck,@day,@month,@year,'daryaft',@CodeVasete,@strShomareSanad output;
										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 output;
										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;
							if @InsertType<>'archive'								
								INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
									VALUES        (@lngCodeUser,@strNameUser,'دریافت','جدید',@lngDateNow,@strtime,@shomaredaryaft,@strShomareSanad)
						end
					else
						begin
							execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@CodeMoinHesabhayeDaryaftani,@CodeTafzili,'1',0,@decjam,@strRadif,@DateDaryaft,@SharheKol,@day,@month,@year,'daryaft',@CodeVasete,@ShomareSanadKarbar;
							if @InsertType<>'archive'								
								INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
									VALUES        (@lngCodeUser,@strNameUser,'دریافت','جدید',@lngDateNow,@strtime,@shomaredaryaft,@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,'0',@lngMablaghPorsant,0,@intRadif,@DateDaryaft,@SharhePoorsant,@day,@month,@year,'daryaft','',@strShomareSanad
											else
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@CodeVasete,'0',@lngMablaghPorsant,0,@intRadif,@DateDaryaft,@SharhePoorsant,@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,'0',0,@lngMablaghPorsant,@intRadif,@DateDaryaft,@SharhePoorsant,@day,@month,@year,'daryaft','',@strShomareSanad
											else
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@CodeVasete,'0',0,@lngMablaghPorsant,@intRadif,@DateDaryaft,@SharhePoorsant,@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,'0',@lngMablaghPorsantSuperVizor,0,@intRadif,@DateDaryaft,@SharhePoorsant,@day,@month,@year,'daryaft','',@strShomareSanad
											else
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@fldCodeSuperVizor,'0',@lngMablaghPorsantSuperVizor,0,@intRadif,@DateDaryaft,@SharhePoorsant,@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,'0',0,@lngMablaghPorsantSuperVizor,@intRadif,@DateDaryaft,@SharhePoorsant,@day,@month,@year,'daryaft','',@strShomareSanad
											else
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeSuperVizor,'0',0,@lngMablaghPorsantSuperVizor,@intRadif,@DateDaryaft,@SharhePoorsant,@day,@month,@year,'daryaft','',@ShomareSanadKarbar
										end 
									
								end 
								--پایان سند پورسانت واسطه ها و ویزیتور ها 


					update tblSodooreSanad set fldColorBank=#tmpColor.fldColorBank,fldColorSandoogh=#tmpColor.fldColorSandoogh,fldColorSooratHesab=#tmpColor.fldColorSooratHesab from #tmpColor Where tblSodooreSanad.fldSanad=@ShomareSanadArchive and fldMoinKamel=#tmpColor.MoinKamel

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


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

					delete tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft  and (fldShomareVosool  is  null and fldShomarePardakht  is  null and fldVaziat is  null) and fldShomareCheck in (Select fldShomareCheck from tblCheckeDaryafti Where fldShomareDaryaft=@ShomareDaryaft and (fldShomareVosool  is not null or fldShomarePardakht  is not null or 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,fldShomareBargashtAzForoosh)
						Select fldShomareFactor, @ShomareDaryaft, fldMablagh ,0   from  @dtTasfie


					INSERT       INTO              tblRizeTasfieVam( fldShomareVam,fldShomareGhest, fldShomareDaryaft, fldMablagh)
						Select fldShomareVam,fldShomareGhest, @ShomareDaryaft, fldMablagh    from  @dtTasfieVam
									

					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

-- ===============================================
-- SP: [dbo].[InsertInfoInPardakht]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoInPardakht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoInPardakht] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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 tblCheckVagozari2  readonly,
@CodeKolCheckVagozari nvarchar(10),
@CodeMoinCheckVagozari nvarchar(10),
@MablaghCheckVagozari decimal,
@SCheckVagozari nvarchar(200),

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


@lngCodeUser bigint,
@lngDateNow bigint,

@karmozd decimal,

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




@NoeKhata nvarchar(30) output 


--@NoeKhata int output
as


create table #tmpColor (
	MoinKamel nvarchar(50) COLLATE Persian_100_CI_AS,
	fldColorBank int,
	fldColorSandoogh int , 
	fldColorSooratHesab int

)

begin
	begin transaction transact
		begin try
			declare @CodeMoinHoghoogh nvarchar(10), @MaxSanad bigint,@lngI bigint,@lngCount bigint,@strShomareSanad nvarchar(50),@lngCountPardakht int,@IDOutPut bigint,@decJam decimal	,@decBankBaKarmozd decimal,@strNameUser nvarchar(25),@strTime nvarchar(30)
			declare @TooleKol bigint,@TooleMoin bigint,@ShomareSanadArchive nvarchar(50),@LngCountVagozari bigint,@lngIVagozari bigint,@DateKamel int,@SharhePoorsant nvarchar(100),@CodeMoinKarmozd nvarchar(10)
	 
			 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 ;
			 set @decBankBaKarmozd=@bank+@karmozd

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

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

			 set @strNameUser=(Select fldUser from tblSecurity Where fldCode=@lngCodeUser)

			 set @strtime=(SELECT ltrim(right(convert(varchar(25), getdate(), 100), 7)))

			 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)
							insert into #tmpColor
								(MoinKamel,fldColorBank ,fldColorSandoogh , fldColorSooratHesab )
								Select fldMoinKamel,fldColorBank,fldColorSandoogh,fldColorSooratHesab from tblSodooreSanad Where fldSanad=@ShomareSanadArchive


							--INSERT INTO tblTest7
							--		(fld1, fld2, fld3)
							--Select fldMoinKamel,fldColorBank,@ShomareSanadArchive from tblSodooreSanad Where fldSanad=@ShomareSanadArchive

							delete from tblSodooreSanad Where fldSanad=@ShomareSanadArchive
							delete from tblCheckePardakhti where fldSanad=@ShomareSanadArchive
							update tblCheckeDaryafti set fldShomarePardakht=null,fldVaziat=NULL Where fldShomarePardakht=@ShomarePardakht
							delete from tblPardakht where fldShomareSanad=@ShomareSanadArchive
							
							set @noekhata='update_archive'

							if @TypePardakht='enteghalevajh' 
								INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
									VALUES        (@lngCodeUser,@strNameUser,'انتقال وجه','ویرایش',@lngDateNow,@strtime,@shomarePardakht,@ShomareSanadArchive)
							
							else if @TypePardakht='hazine' 
								INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
									VALUES        (@lngCodeUser,@strNameUser,'ثبت هزینه','ویرایش',@lngDateNow,@strtime,@shomarePardakht,@ShomareSanadArchive)
							else
								INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
									VALUES        (@lngCodeUser,@strNameUser,'پرداخت','ویرایش',@lngDateNow,@strtime,@shomarePardakht,@ShomareSanadArchive)

							--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

							declare @CodeKolCheckPersonel nvarchar(10),@CodeMoinKhamPersonel nvarchar(10),@strMoinKamelPersonel nvarchar(10)

							if @intRadif=1
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										begin
											if @CodeNoeTafzili='0' --پرداختی به پرسنل
												begin
													execute codemoinhesab 'checkpersonel' ,@strMoinKamelPersonel output
													set @CodeMoinKhamPersonel=substring(@strMoinKamelPersonel,@TooleKol+1,@Toolemoin)
													set @CodeKolCheckPersonel=substring(@strMoinKamelPersonel,1,@TooleKol)
													execute insertSanadFirst @CodeKolCheckPersonel,@CodeMoinKhamPersonel,@strMoinKamelPersonel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad output;
												end
											else --پرداختی به اشخاص																	
													execute insertSanadFirst @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad output;												
										end
									else
										begin
											if @CodeNoeTafzili='0' --پرداختی به پرسنل
												begin
													execute codemoinhesab 'checkpersonel' ,@strMoinKamelPersonel output
													set @CodeMoinKhamPersonel=substring(@strMoinKamelPersonel,@TooleKol+1,@Toolemoin)
													set @CodeKolCheckPersonel=substring(@strMoinKamelPersonel,1,@TooleKol)
													--set @strMoinKamel=@CodeMoinCheck
													execute insertSanadLast @CodeKolCheckPersonel,@CodeMoinKhamPersonel,@strMoinKamelPersonel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;												
													--execute insertSanadLast '317','02','31702',@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;												
												end
											else
												begin									
													execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@strMoinKamel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;
												end


											
											set @strShomareSanad=@ShomareSanadKarbar
										end
								end
							else
								begin
									if @CodeNoeTafzili='0' --پرداختی به پرسنل
										begin
											execute codemoinhesab 'checkpersonel' ,@strMoinKamelPersonel output
											set @CodeMoinKhamPersonel=substring(@strMoinKamelPersonel,@TooleKol+1,@Toolemoin)
											set @CodeKolCheckPersonel=substring(@strMoinKamelPersonel,1,@TooleKol)
											execute insertSanadLast @CodeKolCheckPersonel,@CodeMoinKhamPersonel,@strMoinKamelPersonel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad;
										end 
									else
										begin
											execute insertSanadLast @CodeKolCheck,@CodeMoinCheck,@CodeMoinKhamPersonel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheck,@strRadif,@DatePardakht,@SCheck,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad;
										end

								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,fldVaziat='forooshecheck' 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

							declare @CodeKolCheckVagozariPersonel nvarchar(10),@CodeMoinKhamVagozariPersonel nvarchar(10),@strMoinKamelVagozariPersonel nvarchar(10)

							if @intRadif=1
								begin
									if @ResultSanad='archive' --یعنی این شماره سند که از سمت کاربر اومده تکراریه
										begin
											if @CodeNoeTafzili='0' --پرداختی به پرسنل
												begin
													execute codemoinhesab 'checkvagozaripersonel' ,@strMoinKamelVagozariPersonel output
													set @CodeMoinKhamVagozariPersonel=substring(@strMoinKamelVagozariPersonel,@TooleKol+1,@Toolemoin)
													set @CodeKolCheckVagozariPersonel=substring(@strMoinKamelVagozariPersonel,1,@TooleKol)													
													execute insertSanadFirst @CodeKolCheckVagozariPersonel,@CodeMoinKhamVagozariPersonel,@strMoinKamelVagozariPersonel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheckVagozari,@strRadif,@DatePardakht,@SCheckVagozari,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad output;
												end
											else--پرداختی به اشخاص
												execute insertSanadFirst @CodeKolCheckVagozari,@CodeMoinCheckVagozari,@strMoinKamel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheckVagozari,@strRadif,@DatePardakht,@SCheckVagozari,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad output;
										end
									else
										begin
											--if @CodeNoeTafzili='0' --پرداختی به پرسنل
											--	begin												
											--		execute codemoinhesab 'checkvagozaripersonel' ,@strMoinKamelVagozariPersonel output
											--		set @CodeMoinKhamVagozariPersonel=substring(@strMoinKamelVagozariPersonel,@TooleKol+1,@Toolemoin)
											--		set @CodeKolCheckVagozariPersonel=substring(@strMoinKamelVagozariPersonel,1,@TooleKol)

											--		execute insertSanadLast @CodeKolCheckVagozariPersonel,@CodeMoinKhamVagozariPersonel,@strMoinKamelVagozariPersonel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheckVagozari,@strRadif,@DatePardakht,@SCheckVagozari,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;
											--	end
											--else
											--begin
												declare @cntCheck int,@codeTafziliVagozari nvarchar(30),@EmpId nvarchar(50),@MablaghVagozar decimal

												declare EmpCursor Cursor For
												SELECT fldShomareCheck  FROM @CheckeVagozari											
												open EmpCursor
												fetch Next From EmpCursor into @EmpId
												While @@Fetch_Status = 0
													Begin	
														--ابتدا
																		
															set @strRadif=convert(nvarchar(50),@intRadif)
															set @codeTafziliVagozari=(Select fldCodeSahebeCheck from tblCheckeDaryafti Where fldShomareCheck=convert(varchar,@EmpId))
															set @MablaghVagozar=(Select fldMablagh from tblCheckeDaryafti Where fldShomareCheck=convert(varchar,@EmpId))
															set @cntCheck=(select count(fldShomareCheck) as cnt from @CheckeVagozari)
															execute insertSanadLast @CodeKolCheckVagozari,@CodeMoinCheckVagozari,@strMoinKamel,@codeTafziliVagozari,@CodeNoeTafzili,0,@MablaghVagozar,@strRadif,@DatePardakht,@SCheckVagozari,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;

															set @intRadif =@intRadif+1
														--انتها
														Fetch Next from EmpCursor
														into @EmpId
													end
												Close EmpCurSor
												Deallocate EmpCursor


												set @strShomareSanad=@ShomareSanadKarbar												
											end
											
										--end
								end
							else
								begin
									if @CodeNoeTafzili='0' --پرداختی به پرسنل
										begin												
											execute codemoinhesab 'checkvagozaripersonel' ,@strMoinKamelVagozariPersonel output
											set @CodeMoinKhamVagozariPersonel=substring(@strMoinKamelVagozariPersonel,@TooleKol+1,@Toolemoin)
											set @CodeKolCheckVagozariPersonel=substring(@strMoinKamelVagozariPersonel,1,@TooleKol)
											execute insertSanadLast @CodeKolCheckVagozariPersonel,@CodeMoinKhamVagozariPersonel,@strMoinKamelVagozariPersonel,@CodeTafzili,@CodeNoeTafzili,0,@MablaghCheckVagozari,@strRadif,@DatePardakht,@SCheckVagozari,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad;
										end
									else
										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 output;
										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='pardakhtpersonel'  or @TypePardakht='pardakhtsayer'
						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;

							if @InsertType<>'archive'	
								BEGIN
									if @TypePardakht='enteghalevajh' 
										INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
											VALUES        (@lngCodeUser,@strNameUser,'انتقال وجه','جدید',@lngDateNow,@strtime,@shomarePardakht,@strShomareSanad)
							
									else if @TypePardakht='hazine' 
										INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
											VALUES        (@lngCodeUser,@strNameUser,'ثبت هزینه','جدید',@lngDateNow,@strtime,@shomarePardakht,@strShomareSanad)

									else
										INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
											VALUES        (@lngCodeUser,@strNameUser,'پرداخت','جدید',@lngDateNow,@strtime,@shomarePardakht,@strShomareSanad)
								END

						end
					else
						begin
							execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@CodeMoinHesabhayePardakhtani,@CodeTafzili,@CodeNoeTafzili,@decJam,0,@strRadif,@DatePardakht,@SharheKol,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;
							if @InsertType<>'archive'	
								BEGIN
									if @TypePardakht='enteghalevajh' 
										INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
											VALUES        (@lngCodeUser,@strNameUser,'انتقال وجه','جدید',@lngDateNow,@strtime,@shomarePardakht,@ShomareSanadKarbar)
							
									else if @TypePardakht='hazine' 
										INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
											VALUES        (@lngCodeUser,@strNameUser,'ثبت هزینه','جدید',@lngDateNow,@strtime,@shomarePardakht,@ShomareSanadKarbar)
									else
										INSERT  INTO  tblAmalkardekarbar( fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad)
											VALUES        (@lngCodeUser,@strNameUser,'پرداخت','جدید',@lngDateNow,@strtime,@shomarePardakht,@ShomareSanadKarbar)
								END
						end
					--execute insertSanadLast @CodeKolkham,@CodeMoinKham ,@codemoinhesabhayePardakhtani,NUll,NUll,@decjam,0,@strRadif,@DatePardakht,@SharheKol,@TypePardakht;

					--سند پورسانت واسطه ها و ویزیتور ها
							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 @SharhePoorsant='معکوس پورسانت پرداخت ' + Convert(varchar,@ShomarePardakht)
									--set @lngsum=(@lngMablaghKolFactor-@lngHazineHamlVaNaghl-@lngArzeshAfzode)
									if @lngMablaghPorsant>0 
										begin
											if @ResultSanad='archive'
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@CodeVasete,'0',0,@lngMablaghPorsant,@intRadif,@DatePardakht,@SharhePoorsant,@day,@month,@year,'pardakht','',@strShomareSanad
											else
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@CodeVasete,'0',0,@lngMablaghPorsant,@intRadif,@DatePardakht,@SharhePoorsant,@day,@month,@year,'pardakht','',@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,'0',@lngMablaghPorsant,0,@intRadif,@DatePardakht,@SharhePoorsant,@day,@month,@year,'pardakht','',@strShomareSanad
											else
												execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@CodeVasete,'0',@lngMablaghPorsant,0,@intRadif,@DatePardakht,@SharhePoorsant,@day,@month,@year,'pardakht','',@ShomareSanadKarbar
										end


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

						--کارمزد بانک
							if @karmozd>0
								begin	
									declare @tmp nvarchar(20)								
									set @intRadif=@intRadif+1
									
									execute codemoinhesab 'karmozd' ,@CodeMoinKarmozd output

									
									--set @CodeMoinKarmozd='61226'

									set @CodeKolkham =substring(@CodeMoinKarmozd, 1, @TooleKol)
									set @CodeMoinKham =substring(@CodeMoinKarmozd,@TooleKol+1,@Toolemoin)
									set @SharhePoorsant='کارمزد بانک ' + Convert(varchar,@ShomarePardakht)
									set @tmp=@CodeKolBank + @CodeMoinBank
									
											if @ResultSanad='archive'
												begin
													execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinKarmozd,@CodeVasete,'0',@karmozd,0,@intRadif,@DatePardakht,@SharhePoorsant,@day,@month,@year,'pardakht','',@strShomareSanad
													set @intRadif=@intRadif+1
													execute insertSanadLast @CodeKolBank,@CodeMoinBank,@tmp,NUll,NULL,0,@karmozd,@intRadif,@DatePardakht,@SBank,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad
													--execute insertSanadFirst @CodeKolBank,@CodeMoinBank,@strMoinKamel,NUll,NULL,0,@karmozd,@intRadif,@DatePardakht,@SBank,@day,@month,@year,@TypePardakht,@CodeVasete,@strShomareSanad output	
												end
											else
												begin
													execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinKarmozd,@CodeVasete,'0',@karmozd,0,@intRadif,@DatePardakht,@SharhePoorsant,@day,@month,@year,'pardakht','',@ShomareSanadKarbar
													set @intRadif=@intRadif+1
													execute insertSanadLast @CodeKolBank,@CodeMoinBank,@tmp,NUll,NULL,0,@karmozd,@intRadif,@DatePardakht,@SBank,@day,@month,@year,@TypePardakht,@CodeVasete,@ShomareSanadKarbar;
												end


											set @intRadif=@intRadif+1									
											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)


									
								end 
						--پایان سند پورسانت واسطه ها و ویزیتور ها 
					
					update tblSodooreSanad set fldColorBank=#tmpColor.fldColorBank,fldColorSandoogh=#tmpColor.fldColorSandoogh,fldColorSooratHesab=#tmpColor.fldColorSooratHesab from #tmpColor Where tblSodooreSanad.fldSanad=@ShomareSanadArchive and fldMoinKamel=#tmpColor.MoinKamel

					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 ISNUMERIC(@CodeTafzili)=0
					--	set @CodeTafzili='0'

					--ثبت اطلاعات دریافت
					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)
								--INSERT  INTO   tblPardakht( fldShomarePardakht, fldShomareSanad, fldCodeTafzili,fldType)
								--	VALUES        (@ShomarePardakht,@ShomareSanadKarbar,@CodeTafzili,@TypePardakht)
								--INSERT       INTO              tblTest7(fld1, fld2, fld3)
								--		VALUES        (@TypePardakht,@ShomarePardakht,@ShomareSanadKarbar)
						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

-- ===============================================
-- SP: [dbo].[InsertInfoInTblTanzimatDynamic]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoInTblTanzimatDynamic', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoInTblTanzimatDynamic] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertInfoInTblTanzimatDynamic]
	@strType nvarchar(30),
	@strMeghdar nvarchar(30)
as 

begin
	INSERT       INTO              tblTanzimatDynamic(fldType, fldMeghdar)
				VALUES        (@strtype,@strmeghdar)
end
GO

-- ===============================================
-- SP: [dbo].[InsertInfoIntblTanzimatKol]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoIntblTanzimatKol', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoIntblTanzimatKol] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[InsertInfoKhabanidanCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoKhabanidanCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoKhabanidanCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[InsertInfoKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
Alter PROCEDURE [dbo].[InsertInfoKharid]
@flagKharid nvarchar(10),

--@dtCheckPardakhti tblCheckPardakhti readonly,
--@dtCheckMoshtari tblCheckVagozari readonly,
@intHasRowCheckPardakhti int,
@intHasRowCheckMoshtari int,
@lngMablaghKolCheckHaPardakhti bigint,
@lngMablaghKolCheckMoshtari bigint,



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


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


@lngHazineHamlVaNaghl bigint,
@fldCodeTafziliHaml nvarchar(15),
@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 tblCheckVagozari2 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

create table #tmpColor (
	MoinKamel nvarchar(50) COLLATE Persian_100_CI_AS,
	fldColorBank int,
	fldColorSandoogh int , 
	fldColorSooratHesab int
)
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	,@CodeMoinKarmozd nvarchar(10),@Sharh nvarchar(100)
					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, @SharheArzesheAfzoode nvarchar(100)
					--,@ShomarePardakht bigint,@lngSumPardakht bigint
					set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
					set @year=@yearFull
					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)
					set @dateSmall=@fldDate
					declare @maxFactor bigint
					set @intRadif=0
					set @fldCodeVasete=0

					
					----------End Declare and set Init Values----------
			set @SharheArzesheAfzoode=' شماره خرید ' +  Convert(varchar,@fldShomareFactor)  + ' ' + @fldSharhfactor
			if(@flagKharid='arshive')
				begin
					--delete
						--برای حالتی که چک از حالت فروش در نمیاد
						--UPDATE tblCheckeDaryafti Set fldVaziat=NULL Where fldShomarePardakht=@ShomarePardakht  and fldVaziat='forooshecheck'
						--##############################################################
						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

						insert into #tmpColor
								(MoinKamel,fldColorBank ,fldColorSandoogh , fldColorSooratHesab )
								Select fldMoinKamel,fldColorBank,fldColorSandoogh,fldColorSooratHesab from tblSodooreSanad Where fldSanad=@fldShomareSanad

						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,fldVaziat=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,@SharheArzesheAfzoode,@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)
					--بستانکار
					if ISNUMERIC(@fldCodeTafziliHaml)=1 
						begin
							declare @decmMablaghWithoutHaml decimal(18,0)							
							set @lngMablaghKolFactor=@lngMablaghKolFactor-@lngHazineHamlVaNaghl
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
							set @intRadif=@intRadif+1
							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafziliHaml,'1',0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
						end
					else
						execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,@fldSharhFactor,@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 , fldVaziat='forooshecheck' Where Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) in (Select Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) from @CheckeVagozari)

					end
					--کارمزد بانک
					if @karmozd>0
						begin		
							declare @Karmozd2 nvarchar(10)
							set @intRadif=@intRadif+1
									
							execute codemoinhesab 'karmozd' ,@CodeMoinKarmozd output

									
							--set @CodeMoinKarmozd='61226'

							set @CodeKolkham =substring(@CodeMoinKarmozd, 1, @TooleKol)
							set @CodeMoinKham =substring(@CodeMoinKarmozd,@TooleKol+1,@Toolemoin)
							set @Sharh='کارمزد بانک ' + Convert(varchar,@ShomarePardakht) 
									

							execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinKarmozd,NULL,'0',@karmozd,0,@intRadif,@fldDate,@Sharh,@day,@month,@year,'kharid','',@fldShomareSanad
							set @intRadif=@intRadif+1
							set @Karmozd2=@CodeKolBank+ @CodeMoinBank
							execute InsertSanadLast @CodeKolBank,@CodeMoinBank,@Karmozd2,NUll,NULL,0,@karmozd,@intRadif,@fldDate,@Sharh,@day,@month,@year,'kharid','',@fldShomareSanad	
													
									
						end 
					-----------------------factor--------------------------------------

					set @maxFactor=@fldShomarefactor


					INSERT INTO tblKharid ([fldShomareFactorKharid],[fldShomareSanad],[fldDate],[fldDateSarResid],[fldSharhFactor])
						values(@maxFactor,@fldShomareSanad,@fldDate,@fldDateSarResid, @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],[fldDateEngheza],[fldbatchnumber],[fldDateSakht])
						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],[fldDateEngheza],[fldbatchnumber],[fldDateSakht]
						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,@SharheArzesheAfzoode,@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)
									--بستانکار

									if ISNUMERIC(@fldCodeTafziliHaml)=1 
										begin
											declare @decmMablaghWithoutHaml2 decimal(18,0)							
											set @lngMablaghKolFactor=@lngMablaghKolFactor-@lngHazineHamlVaNaghl
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
											set @intRadif=@intRadif+1
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafziliHaml,'1',0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
										end
									else
										execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
										--execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,@fldSharhFactor,@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 , fldVaziat='forooshecheck' Where Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) in (Select Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) from @CheckeVagozari)



									--کارمزد بانک
									if @karmozd>0
										begin				
											declare @Karmozd3 nvarchar(10)
											set @intRadif=@intRadif+1
									
											execute codemoinhesab 'karmozd' ,@CodeMoinKarmozd output

									
											--set @CodeMoinKarmozd='61226'

											set @CodeKolkham =substring(@CodeMoinKarmozd, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinKarmozd,@TooleKol+1,@Toolemoin)
											set @Sharh='کارمزد بانک ' + Convert(varchar,@ShomarePardakht) 
									

											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinKarmozd,NULL,'0',@karmozd,0,@intRadif,@fldDate,@Sharh,@day,@month,@year,'kharid','',@fldShomareSanad
											set @intRadif=@intRadif+1
											set @Karmozd3=@CodeKolBank+ @CodeMoinBank
											execute InsertSanadLast @CodeKolBank,@CodeMoinBank,@Karmozd3,NUll,NULL,0,@karmozd,@intRadif,@fldDate,@Sharh,@day,@month,@year,'kharid','',@fldShomareSanad	
													
									
										end 


									end

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

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

									INSERT INTO tblKharid ([fldShomareFactorKharid],[fldShomareSanad],[fldDate],[fldDateSarResid],[fldSharhFactor])
									values(@maxFactor,@fldShomareSanad,@fldDate,@flddateSarResid, @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],[fldDateEngheza],[fldbatchnumber],[fldDateSakht])
									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],[fldDateEngheza],[fldbatchnumber],[fldDateSakht]
									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,@SharheArzesheAfzoode,@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)
									--بستانکار
									
									if ISNUMERIC(@fldCodeTafziliHaml)=1 
										begin											
											set @lngMablaghKolFactor=@lngMablaghKolFactor-@lngHazineHamlVaNaghl
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
											set @intRadif=@intRadif+1
											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafziliHaml,'1',0,@lngHazineHamlVaNaghl,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
										end
									else
										execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,@fldSharhFactor,@day,@month,@year,'kharid',@fldCodeVasete,@fldShomareSanad
										--execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@fldCodeTafsili,'1',0,@lngMablaghKolFactor,@intRadif,@dateSmall,@fldSharhFactor,@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 , fldVaziat='forooshecheck' Where Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) in (Select Convert(nvarchar,fldShomareCheck) + Convert(nvarchar,fldShomareHesab) from @CheckeVagozari)

									end


									--کارمزد بانک
									if @karmozd>0
										begin									
											set @intRadif=@intRadif+1
											declare @Karmozd1 nvarchar(10) 
											execute codemoinhesab 'karmozd' ,@CodeMoinKarmozd output

									
											--set @CodeMoinKarmozd='61226'

											set @CodeKolkham =substring(@CodeMoinKarmozd, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinKarmozd,@TooleKol+1,@Toolemoin)
											set @Sharh='کارمزد بانک ' + Convert(varchar,@ShomarePardakht) 
									

											execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinKarmozd,NULL,'0',@karmozd,0,@intRadif,@fldDate,@Sharh,@day,@month,@year,'kharid','',@fldShomareSanad
											set @intRadif=@intRadif+1

											set @Karmozd1=@CodeKolBank+ @CodeMoinBank
											execute InsertSanadLast @CodeKolBank,@CodeMoinBank,@Karmozd1,NUll, NULL,0,@karmozd,@intRadif,@fldDate,@Sharh,@day,@month,@year,'kharid','',@fldShomareSanad 	

											
													
									
										end 

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

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

									INSERT INTO tblKharid ([fldShomareFactorKharid],[fldShomareSanad],[fldDate],[fldDateSarResid],[fldSharhFactor])
									values(@maxFactor,@fldShomareSanad,@fldDate,@fldDateSarResid,@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],[fldDateEngheza],[fldbatchnumber],[fldDateSakht])
									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],[fldDateEngheza],[fldbatchnumber],[fldDateSakht]
									output from @dtKharid;
									set @strResult=convert(nvarchar(17),@maxFactor)
									set @strResult2='insert'
									set @flagInsert='yes_byNo'
						end
			

			end


			update tblSodooreSanad set fldColorBank=#tmpColor.fldColorBank,fldColorSandoogh=#tmpColor.fldColorSandoogh,fldColorSooratHesab=#tmpColor.fldColorSooratHesab from #tmpColor Where tblSodooreSanad.fldSanad=@fldShomareSanad and fldMoinKamel=#tmpColor.MoinKamel

			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

-- ===============================================
-- SP: [dbo].[InsertInfoMojodiEbtedaDoreh]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoMojodiEbtedaDoreh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoMojodiEbtedaDoreh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[InsertInfoMojodiEbtedaDoreh2]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoMojodiEbtedaDoreh2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoMojodiEbtedaDoreh2] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[InsertInfoMojodiEbtedaDoreh2]
   -- @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,@SumKol varchar(50) 
    -- 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 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,' ')

								Delete from tblSodooreSanad where fldSanad=@ShomareSanad And fldType='mojoodieebteda'
							     set @strResult='DeleteOk'
                       End
                  End
                
				 if (@lngCountMojodi > 0)
			       Begin
				   Delete from tblSodooreSanad where fldSanad=@ShomareSanad And fldType='mojoodieebteda'
					Set @SumKol=(Select SUM(fldFeeKol) from tblRizeKharid where fldType='mojodi_ebteda_doreh')
				      if @InsertType='insert'
					    begin


								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

-- ===============================================
-- SP: [dbo].[InsertInfoMojodiEbtedaDorehNew]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoMojodiEbtedaDorehNew', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoMojodiEbtedaDorehNew] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[InsertInfoMojodiEbtedaDorehNew]
    @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),
	@Sanad int
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 @ShomareSanad=(Select top 1(fldSanad)  from tblSodooreSanad Where fldType='mojoodieebteda')
				if isnumeric(@ShomareSanad )=0
					begin

						set @ShomareSanad =(Select Max(Convert(bigint,fldSanad)) from tblSodooreSanad)
						if ISNUMERIC(@ShomareSanad )=1
							set @ShomareSanad=@ShomareSanad + 1
						else
							set @ShomareSanad=1

					end 
					
		     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;

							if @sanad=1
								begin
									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,' ')
								end

							     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;
							if @sanad=1
								begin
									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,' ')

								end
							     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

-- ===============================================
-- SP: [dbo].[InsertInfoPaseCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoPaseCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoPaseCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[InsertInfoPaseCheck]
	@fldShomarePas bigint,
	@fldSanadPas bigint,
	@strResult nvarchar(25) output,
	@InsertType nvarchar(50)  ,	
	@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
			
			set @intRadif=0

			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	
							declare @SanadCheckPardakhti bigint
						--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)


							set @ShomareCheck= (Select fldShomareCheck from tblCheckePardakhti Where id =@EmpId)
							set @SanadCheckPardakhti=(select fldSanad from tblCheckePardakhti Where id =@EmpId)


							declare @TypeKharid nvarchar(10),@MoinhesabPardakhti nvarchar(10)

							execute CodeMoinHesab 'hesabhayepardakhtani',@MoinhesabPardakhti output


							set @TypeKharid= (select top(1) fldtype from tblSodooreSanad Where fldSanad=@SanadCheckPardakhti )
							if @TypeKharid='kharid' or @SanadCheckPardakhti=0
								execute CodeMoinHesab 'checkpardakhti',@strMoinKamel  output
							else
								set @strMoinKamel=(select top(1)fldmoinkamel from tblSodooreSanad Where fldSanad=@SanadCheckPardakhti and ISNUMERIC(fldcodeTafzili)=1   and fldMoinKamel<>@MoinhesabPardakhti)
							--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=@Date--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), 1, 4)

							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 @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 output;
									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

-- ===============================================
-- SP: [dbo].[InsertInfoPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[InsertInfoPishForoosh]
	@flagForoosh nvarchar(10),
	@MultiFee bigint,
	@fldCodeTafsili bigint,

	@fldCodeVasete nvarchar(10),
	@lngMablaghPorsant bigint,

	@fldCodeSuperVizor nvarchar(10),
	@lngMablaghPorsantSuperVizor bigint,

    @fldShomareFactor bigint,
    --@fldShomareSanad bigint,
    @fldDate bigint,
	@fldSharhFactor nvarchar(250),
	@dtForoosh tpRizePishForoosh2  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]
							   ,[fldCodeFeeDynamic]
							   )
								 values(@fldShomareFactor,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end,@MultiFee )
								 
							 INSERT INTO tblRizePishForoosh						   
						    ([fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldDarsadArzeshAfzoode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldEshantion]
						   ,[fldTime])
							select
							@fldShomareFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldDarsadArzeshAfzoode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldEshantion]
						   ,[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]
							   ,[fldCodeFeeDynamic]
							   )							   
								 values(@maxFactor,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end ,@MultiFee)

							 INSERT INTO tblRizePishForoosh						   
						    ([fldShomareFactor]
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldDarsadArzeshAfzoode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldEshantion]
						   ,[fldTime])
							select 
						    @maxFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldDarsadArzeshAfzoode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldEshantion]
						   ,[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]
							   ,[fldCodeFeeDynamic]
							   )
								 values(@fldShomareFactor,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end,@MultiFee )

							 INSERT INTO tblRizePishForoosh
													   ([fldShomareFactor]
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldDarsadArzeshAfzoode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldEshantion]
													   ,[fldTime])
														select 
														--edit
													    @fldShomareFactor
													   ,[fldCodeVasete]
													   ,[fldCodeTafsili]
													   ,[fldCodeUser]
													   ,[fldRadif]
													   ,[fldCodeAnbar]
													   ,[fldCodeKala]
													   ,[fldSharhKala]
													   ,[fldTedadCarton]
													   ,[fldTedadJoz]
													   ,[fldFeeJoz]
													   ,[fldFeeYekCarton]
													   ,[fldFeeKol]
													   ,[fldDarsadTakhfif]
													   ,[fldMablaghTakhfif]
													   ,[fldFeeVahed1BadAzTakhfif]
													   ,[fldFeeVahed2BadAzTakhfif]
													   ,[fldArzeshAfzode]
													   ,[fldDarsadArzeshAfzoode]
													   ,[fldFeeKolBadAzTakhfif]
													   ,[fldMablaghKhales]
													   ,[fldType]
													   ,[fldDate]
													   ,[fldEshantion]
													   ,[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

-- ===============================================
-- SP: [dbo].[InsertInfoPishPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoPishPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoPishPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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,case when @fldSharhFactor='none' then '' else @fldSharhFactor end )
								 
							 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,case when @fldSharhFactor='none' then '' else @fldSharhFactor end )

							 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,case when @fldSharhFactor='none' then '' else @fldSharhFactor end )

							 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

-- ===============================================
-- SP: [dbo].[InsertInfoPishPishForooshNew]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoPishPishForooshNew', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoPishPishForooshNew] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[InsertInfoPishPishForooshNew]
	@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 tpRizeForoosh8  readonly,
	@dtCheckDaryafti tblCheckDaryafti readonly,
	@lngHazineHamlVaNaghl bigint,
	@lngArzeshAfzode bigint,
	@lngMablaghKolFactor bigint,
	@lngMablaghKolCheckHa bigint,
	@intHasRowCheckDaryafti int,
	@lngMablaghNaghdDaryaft bigint,
    @lngMablaghBankDaryaft bigint,
	@lngMablaghTakhfifDaryaft bigint,
	@lngCodeSandoghDaryaft bigint,
	@lngCodeBankDaryaft bigint,
	@lngShomareForoosh bigint,
	@strAmani nvarchar(5), 
	--شرح دریافت
	@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]
							   ,[fldShomareForoosh]
							   ,[fldAmani]
							   )
								 values(@fldShomareFactor,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end,@lngShomareForoosh ,@strAmani)
								 
							 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]
						   ,[fldCodeMasterEshantion])
							select
							@fldShomareFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime]
						   ,[fldCodeMasterEshantion] 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]
							    ,[fldShomareForoosh]
								,[fldAmani]
							   )							   
								 values(@maxFactor,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end,@lngShomareForoosh,@strAmani )

							 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]
						   ,[fldCodeMasterEshantion])
							select 
						    @maxFactor
						   ,[fldCodeVasete]
						   ,[fldCodeTafsili]
						   ,[fldCodeUser]
						   ,[fldRadif]
						   ,[fldCodeAnbar]
						   ,[fldCodeKala]
						   ,[fldSharhKala]
						   ,[fldTedadCarton]
						   ,[fldTedadJoz]
						   ,[fldFeeJoz]
						   ,[fldFeeYekCarton]
						   ,[fldFeeKol]
						   ,[fldDarsadTakhfif]
						   ,[fldMablaghTakhfif]
						   ,[fldFeeVahed1BadAzTakhfif]
						   ,[fldFeeVahed2BadAzTakhfif]
						   ,[fldArzeshAfzode]
						   ,[fldFeeKolBadAzTakhfif]
						   ,[fldMablaghKhales]
						   ,[fldType]
						   ,[fldDate]
						   ,[fldTime]
						   ,[fldCodeMasterEshantion] 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]
							   ,[fldShomareForoosh]
							   ,[fldAmani]
							   )
								 values(@fldShomareFactor,@fldDate,case when @fldSharhFactor='none' then '' else @fldSharhFactor end,@lngShomareForoosh,@strAmani )

							 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]
													   ,[fldCodeMasterEshantion])
														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]
													   ,[fldCodeMasterEshantion] 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

-- ===============================================
-- SP: [dbo].[InsertInfoTblTanzimatDynamic]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoTblTanzimatDynamic', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoTblTanzimatDynamic] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertInfoTblTanzimatDynamic]
	@strType nvarchar(30),
	@strMeghdar nvarchar(30)
as 

begin
	INSERT       INTO              tblTanzimatDynamic(fldType, fldMeghdar)
				VALUES        (@strtype,@strmeghdar)
end
GO

-- ===============================================
-- SP: [dbo].[InsertInfoVosoolCheck_Final]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInfoVosoolCheck_Final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInfoVosoolCheck_Final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[InsertInfoVosoolCheck_Final] 
@fldShomareVosool bigint,
@fldSanadVosool bigint,
@strResult nvarchar(25) output,
@InsertType nvarchar(50),
@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,
						   fldDateBargasht=Null
					  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),@CodeVasete 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)
									set @CodeVasete=(select fldVasete  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),0,5)
									set @month=substring(convert(nvarchar(20),@Tarikh),5,2)
									set @day=substring(convert(nvarchar(20),@Tarikh),7,2)
									set @dateSmall=@Tarikh--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',@CodeVasete,@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)
											


											----سند پورسانت
											declare @CodeKolkham nvarchar(50),@CodeMoinKham nvarchar(50),@CodeMoinHesabhayePardakhtani nvarchar(50)



											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											set @intRow =@intRow + 1

											declare @NoeMohasebePoorsant int,@decDarsadPoorsant decimal(18,2),@DecMablaghePoorsant decimal(18,2),@CodeMoinHoghoogh nvarchar(50)
											set @NoeMohasebePoorsant=(Select fldNoeMohasebePoorsant  from tblTafzili Where fldCodeTafzili= @CodeVasete)
											if @NoeMohasebePoorsant=2 --نوع محاسبه واریزی
												begin
													set @decDarsadPoorsant=(Select fldPoorsant from tblTafzili Where fldCodeTafzili= @CodeVasete)
													set @DecMablaghePoorsant=@Mablagh*@decDarsadPoorsant/100


													set @intRow=@intRow+1
									
													execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
													set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
													set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
													--سند بدهکاری پورسانت
													execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@CodeVasete,'1',@DecMablaghePoorsant,0,@intRow,@dateSmall,'پورسانت',@day,@month,@year,'Vosool','',@fldSanadVosool

													execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
													set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
													set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)

													--سند بستانکاری پورسانت
													set @intRow=@intRow+1
													execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@CodeVasete,'0',0,@DecMablaghePoorsant,@intRow,@dateSmall,'پورسانت',@day,@month,@year,'Vosool','',@fldSanadVosool
												end

										 -- execute insertSanadLast @fldCodhesabKol ,@fldCodHesabMoin,@OutCountMoin,@CodeSahebeCheck,'0',
											--0,@Mablagh,@intRow,@dateSmall,@strTozihateVShomareCheck,@day,@month,@year,'Vosool',NULL,@fldSanadVosool; 
										  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',@CodeVasete,@fldSanadVosool; 

											
											----سند پورسانت
											--declare @CodeKolkham nvarchar(50),@CodeMoinKham nvarchar(50),@CodeMoinHesabhayePardakhtani nvarchar(50)



											execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
											set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
											set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
											set @intRow =@intRow + 1

											--declare @NoeMohasebePoorsant int,@decDarsadPoorsant decimal(18,2),@DecMablaghePoorsant decimal(18,2),@CodeMoinHoghoogh nvarchar(50)
											set @NoeMohasebePoorsant=(Select fldNoeMohasebePoorsant  from tblTafzili Where fldCodeTafzili= @CodeVasete)
											if @NoeMohasebePoorsant=2 --نوع محاسبه واریزی
												begin
													set @decDarsadPoorsant=(Select fldPoorsant from tblTafzili Where fldCodeTafzili= @CodeVasete)
													set @DecMablaghePoorsant=@Mablagh*@decDarsadPoorsant/100


													set @intRow=@intRow+1
									
													execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output
													set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
													set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
													--سند بدهکاری پورسانت
													execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@CodeVasete,'1',@DecMablaghePoorsant,0,@intRow,@dateSmall,'پورسانت',@day,@month,@year,'Vosool','',@fldSanadVosool

													execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
													set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
													set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)

													--سند بستانکاری پورسانت
													set @intRow=@intRow+1
													execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@CodeVasete,'0',0,@DecMablaghePoorsant,@intRow,@dateSmall,'پورسانت',@day,@month,@year,'Vosool','',@fldSanadVosool
												end
											 --//// 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),0,5)
								set @month3=substring(convert(nvarchar(20),@Tarikh3),5,2)
								set @day3=substring(convert(nvarchar(20),@Tarikh3),7,2)
								set @dateSmall3=@Tarikh3--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',@CodeVasete,@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',@CodeVasete,@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
			 		
					--// 
					--insert into tbltest2 (name) values ('2')
						if @InsertType='archive'
							begin
							   --insert into tbltest2 (name) values ('3')
							   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
								 --insert into tbltest2 (name) values ('4')
								 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 
								  --insert into tbltest2 (name) values ('1')
								--------///
							------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),0,5)
										set @month4=substring(convert(nvarchar(20),@Tarikh4),5,2)
										set @day4=substring(convert(nvarchar(20),@Tarikh4),7,2)
										set @dateSmall4=@Tarikh4--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',@CodeVasete,@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',@CodeVasete,@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
								 --insert into tbltest2 (name) values ('5')
							   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),0,5)
									set @month5=substring(convert(nvarchar(20),@Tarikh5),5,2)
									set @day5=substring(convert(nvarchar(20),@Tarikh5),7,2)
									set @dateSmall5=@Tarikh5--substring(convert(nvarchar(15),@Tarikh5),3,6)
									--//Tarikh

										
								set @CodeVasete=(select fldVasete  from tblCheckeDaryafti where ID=@IDVosool5)
												   		--/*insert to tblVosool
										if @intRow5=1
										 begin
											--insert into tbltest2 (name) values ('7')
											--insert into tbltest2 (name) values (@IDVosool5)
											execute InsertSanadLast @fldCodhesabKol5,@fldCodHesabMoin5,@CodeHesab5,NUll,NULL,
										   @Mablagh5,0,@intRow5,@dateSmall5,@Tozihate5,@day5,@month5,@year5,'Vosool',@codevasete,@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)
										  
												----سند پورسانت
												--declare @CodeKolkham nvarchar(50),@CodeMoinKham nvarchar(50),@CodeMoinHesabhayePardakhtani nvarchar(50)
											

												execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
												set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
												set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
												set @intRow =@intRow + 1

												--declare @NoeMohasebePoorsant int,@decDarsadPoorsant decimal(18,2),@DecMablaghePoorsant decimal(18,2),@CodeMoinHoghoogh nvarchar(50)
												set @NoeMohasebePoorsant=(Select fldNoeMohasebePoorsant  from tblTafzili Where fldCodeTafzili= @CodeVasete)
												--insert into tbltest2 (name) values (@CodeVasete)
												--set @CodeVasete=(select *  from tblCheckeDaryafti where ID=24)
												--insert into tbltest2 (name) values (@CodeVasete)
												if @NoeMohasebePoorsant=2 --نوع محاسبه واریزی
														begin
															--insert into tbltest2 (name) values ('8')
															set @decDarsadPoorsant=(Select fldPoorsant from tblTafzili Where fldCodeTafzili= @CodeVasete)
															--insert into tbltest2 (name) values (@CodeVasete)
															set @DecMablaghePoorsant=@Mablagh5*@decDarsadPoorsant/100
															
															set @intRow5=@intRow5+1
															
															execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output

															execute  ToolePaye 'kol',@TooleKol output
															execute  ToolePaye 'moin',@Toolemoin output
															set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
															set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
															declare @MoinKamel2 nvarchar(20)

															set @moinKamel2=( @CodeKolkham  +  @CodeMoinKham)
															--سند بدهکاری پورسانت
															execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@CodeVasete,'1',@DecMablaghePoorsant,0,@intRow5,@dateSmall5,'پورسانت',@day5,@month5,@year5,'Vosool','',@fldSanadVosool

															execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
															set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
															set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)

															--سند بستانکاری پورسانت
															set @intRow5=@intRow5+1
															execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@CodeVasete,'0',0,@DecMablaghePoorsant,@intRow5,@dateSmall5,'پورسانت',@day5,@month5,@year5,'Vosool','',@fldSanadVosool
														end

										  End

										else
										 begin
											--insert into tbltest2 (name) values ('8')
											   set @intRow5 =@intRow5 +1
											  execute insertSanadLast @fldCodhesabKol5 ,@fldCodHesabMoin5,@CodeHesab5,NULL,'1',
											  @Mablagh5,0,@intRow5,@dateSmall5,@Tozihate5,@day5,@month5,@year5,'Vosool',@CodeVasete,@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; 


											
												----سند پورسانت
												--declare @CodeKolkham nvarchar(50),@CodeMoinKham nvarchar(50),@CodeMoinHesabhayePardakhtani nvarchar(50)
												execute  ToolePaye 'kol',@TooleKol output
												execute  ToolePaye 'moin',@Toolemoin output

												execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
												set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
												set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)
			
												set @intRow =@intRow + 1

												--declare @NoeMohasebePoorsant int,@decDarsadPoorsant decimal(18,2),@DecMablaghePoorsant decimal(18,2),@CodeMoinHoghoogh nvarchar(50)
												set @NoeMohasebePoorsant=(Select fldNoeMohasebePoorsant  from tblTafzili Where fldCodeTafzili= @CodeVasete)
												if @NoeMohasebePoorsant=2 --نوع محاسبه واریزی
													begin
														set @decDarsadPoorsant=(Select fldPoorsant from tblTafzili Where fldCodeTafzili= @CodeVasete)
														set @DecMablaghePoorsant=@Mablagh5*@decDarsadPoorsant/100


														set @intRow5=@intRow5+1
									
														execute codemoinhesab 'hoghoogh' ,@CodeMoinHoghoogh output

														execute  ToolePaye 'kol',@TooleKol output
														execute  ToolePaye 'moin',@Toolemoin output
														set @CodeKolkham =substring(@CodeMoinHoghoogh, 1, @TooleKol)
														set @CodeMoinKham =substring(@CodeMoinHoghoogh,@TooleKol+1,@Toolemoin)
												
														--سند بدهکاری پورسانت
														execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHoghoogh,@CodeVasete,'1',@DecMablaghePoorsant,0,@intRow5,@dateSmall5,'پورسانت',@day5,@month5,@year5,'Vosool','',@fldSanadVosool

														execute codemoinhesab 'hesabhayepardakhtanipoorsant' ,@CodeMoinHesabhayePardakhtani output
														set @CodeKolkham =substring(@CodeMoinHesabhayePardakhtani, 1, @TooleKol)
														set @CodeMoinKham =substring(@CodeMoinHesabhayePardakhtani,@TooleKol+1,@Toolemoin)

														--سند بستانکاری پورسانت
														set @intRow5=@intRow5+1
														execute InsertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayePardakhtani,@CodeVasete,'0',0,@DecMablaghePoorsant,@intRow5,@dateSmall5,'پورسانت',@day5,@month5,@year5,'Vosool','',@fldSanadVosool
													end
											  --// 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

-- ===============================================
-- SP: [dbo].[InsertInTblPrinters]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertInTblPrinters', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertInTblPrinters] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[InsertIntoTblIDChapgarKala]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertIntoTblIDChapgarKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertIntoTblIDChapgarKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[InsertKolMoin]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertKolMoin', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertKolMoin] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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 )
	if @IDHesab=@CodeKolHesab + '99'  --یعنی کد پرشده
		begin 
			set @flagSabt=-1
			set @IDOutPut=-1
		end 
	else
		begin	
			Set @IDHesab+=1
			insert into tblKolMoin 
				(fldCodeHesab, fldSharheHesab, fldNoeHesab, fldCodeNoeHesab, fldMarkazFirst, fldMarkazSecond, fldNoe)
				values(@IDHesab,@NameHesab,@SharheNoeTafzili,@CodeType,'غير فعال','غير فعال',null)
			set @flagSabt=@IDHesab
			set @IDOutPut=@@IDENTITY
		end
end
GO

-- ===============================================
-- SP: [dbo].[InsertSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[InsertSanadFirst]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertSanadFirst', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertSanadFirst] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertSanadFirst]
	@fldCodeKol nvarchar(50),
	@fldCodeMoin nvarchar(50),
	@fldMoinKamel nvarchar(50),
	@fldCodeTafzili nvarchar(50),
	@fldCodeNoeTafzili nvarchar(50),
	@fldBedehkar decimal(18, 2),
	@fldBestankar  decimal(18, 2), 
	@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,@yearSmall nvarchar(5)

		if @fldSharh is null
			set @fldSharh=''

		--if len(@year)>2
		--	set @yearSmall=substring(@year,3,2)
		--else
			set @yearSmall=@year

		
		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,@yearSmall,@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,@yearSmall,@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

-- ===============================================
-- SP: [dbo].[InsertSanadFirstWithMarkaz]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertSanadFirstWithMarkaz', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertSanadFirstWithMarkaz] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertSanadFirstWithMarkaz]
	@fldCodeKol nvarchar(50),
	@fldCodeMoin nvarchar(50),
	@fldMoinKamel nvarchar(50),
	@fldCodeTafzili nvarchar(50),
	@fldCodeNoeTafzili nvarchar(50),
	@fldCodeMarkaz1 nvarchar(50),
	@fldCodeMarkaz2 nvarchar(50),
	@fldBedehkar decimal(18, 2),
	@fldBestankar  decimal(18, 2), 
	@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,@yearSmall nvarchar(5)

		if @fldSharh is null
			set @fldSharh=''

		--if len(@year)>2
		--	set @yearSmall=substring(@year,3,2)
		--else
			set @yearSmall=@year

		
		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,''),@fldCodeMarkaz1,@fldCodeMarkaz2,@fldBedehkar,@fldBestankar,@fldRadif,@fldDate,@fldSharh,@day,@month,@yearSmall,@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,''),@fldCodeMarkaz1,@fldCodeMarkaz2,@fldBedehkar,@fldBestankar,@fldRadif,@fldDate,@fldSharh,@day,@month,@yearSmall,@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

-- ===============================================
-- SP: [dbo].[InsertSanadLast]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertSanadLast', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertSanadLast] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertSanadLast]
	@fldCodeKol nvarchar(50),
	@fldCodeMoin nvarchar(50),
	@fldMoinKamel nvarchar(50),
	@fldCodeTafzili nvarchar(50),
	@fldCodeNoeTafzili nvarchar(50),
	@fldBedehkar decimal(18, 2),
	@fldBestankar  decimal(18, 2), 
	@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,@yearSmall nvarchar(5)

		set @yearSmall=@year
		--if len(@year)>2
		--	set @yearSmall=substring(@year,3,2)
		--else
		--	set @yearSmall=@year

		--if len(@fldDate)=8
		--	set @fldDate=RIGHT(@fldDate,6)

		if @fldSharh is null
			set @fldSharh=''
		
		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,@yearSmall,@vasete, @fldType)

		--insert into tblTest7
		--	(fld4)
		-- values	(@fldBestankar)

		--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

-- ===============================================
-- SP: [dbo].[InsertSanadNew]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertSanadNew', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertSanadNew] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[InsertSanadNew]	
	@Sanad bigint,
	@Date bigint,
	@dtSanad dtSanadNew2 readonly,
	@flagInsert nvarchar(10),
	@SanadSaved bigint output,
	@strResult nvarchar(25) output,
	@strResult2 nvarchar(25) output
AS



BEGIN

	begin transaction AddRecord
		begin try			
			declare @intCount bigint

			if @flagInsert='arshive'
				delete tblSodooreSanad Where fldsanad=@Sanad

			if @sanad=0 --یعنی اتوماتیک سند بزن
				begin
					set @intCount=(select count(fldSanad) from tblSodooreSanad )
					if @intcount=0 --یعنی سند اولیه
						set @Sanad=1
					else
						set @Sanad=(Select Max(Convert(dec,fldSanad)) as maxSanad from tblSodooreSanad)+1

					set @SanadSaved=@Sanad
				end
			else
				begin
					set @intcount=(select count(fldSanad) from tblSodooreSanad Where fldSanad=@Sanad)
					if @intCount>0 
						begin
							set @strResult2='tekrari'
							rollback transaction AddRecord;
							return
						end
				end


			
			INSERT        INTO              tblSodooreSanad( fldSanad, fldDay, fldMonth, fldYear, fldCodeKol, fldCodeMoin, fldCodeTafzili, fldCodeMarkaz1, fldCodeMarkaz2, fldBedehkar, fldBestankar, 
											 fldRadif,  fldDate, fldSharh, fldMoinKamel, fldCodeNoeTafzili,      
											 fldType,fldCodeVasete2   )
					select @sanad, fldDay, fldMonth, fldYear, fldCodeKol, fldCodeMoin, fldCodeTafzili, fldCodeMarkaz1, fldCodeMarkaz2, fldBedehkar, fldBestankar, 
											 fldRadif,  @date, fldSharh, fldMoinKamel, fldCodeNoeTafzili,      
											 fldType ,fldCodeVasete2   from @dtSanad
			set @SanadSaved=@Sanad
				
			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

-- ===============================================
-- SP: [dbo].[InsertSandoogh]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertSandoogh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertSandoogh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[InsertSandoogh]
@NameSandoogh nvarchar(50),
@intCode int output,
@idSabt int output
as
begin
		declare @strCodeKoleHesab nvarchar(10)
		execute CodeKolHesab 'sandoogh',@strCodeKoleHesab output

		execute InsertKolMoin '1000',@NameSandoogh,@strCodeKoleHesab,'تفصيلي ندارد','4',@intCode,@idSabt
end
GO

-- ===============================================
-- SP: [dbo].[InsertSandooghNew]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertSandooghNew', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertSandooghNew] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertSandooghNew]

@IDHesab bigInt,
@NameHesab nvarChar(70),
@CodeKolHesab nvarChar(8),
@CodeType nvarchar(5),
@SharheNoeTafzili nvarchar(20),
@ShomareHesab nvarchar(50),
@Mande decimal(18,0),
@fldDate bigint,
@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 
				 ( fldCodeHesab, fldSharheHesab, fldNoeHesab, fldCodeNoeHesab, fldMarkazFirst, fldMarkazSecond, fldNoe, fldInfo)
		values(@IDHesab,@NameHesab,@SharheNoeTafzili,@CodeType,'غير فعال','غير فعال',null,@ShomareHesab)


		--#################################INSERT SANAD####################################
		if @Mande>0
			begin
				declare @TooleKol bigint,@Toolemoin bigint,@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@yearFull int,@year int,@month int,@day int,@fldShomareSanad bigint,@fldCodeKolSarmaye int
				execute  ToolePaye 'kol',@TooleKol output
				execute  ToolePaye 'moin',@Toolemoin output
				--execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
				set @CodeKolkham =substring(convert(varchar,@IDHesab), 1, @TooleKol)
				set @CodeMoinKham =substring(convert(varchar,@IDHesab),@TooleKol+1,@Toolemoin)

				set @yearFull=substring(convert(nvarchar(20),@fldDate),0,5)
				set @year=@yearFull
				set @month=substring(convert(nvarchar(20),@fldDate),5,2)
				set @day=substring(convert(nvarchar(20),@fldDate),7,2)

				execute CodeKolHesab 'sarmaye',@fldCodeKolSarmaye output

				delete from tblSodooreSanad where fldType='mandesandoogh' and fldMoinKamel=@IDHesab

				execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@IDHesab,'','1',@Mande,0,1,@fldDate,'مانده ابتدای دوره صندوق',@day,@month,@year,'mandesandoogh','',@fldShomareSanad output 
				execute InsertSanadLast @fldCodeKolSarmaye,'',@fldCodeKolSarmaye,'','',0,@Mande,2,@fldDate,'مانده ابتدای دوره صندوق',@day,@month,@year,'mandesandoogh','',@fldShomareSanad
			end
		--#################################################################################

	set @flagSabt=@IDHesab
	set @IDOutPut=@@IDENTITY
end
GO

-- ===============================================
-- SP: [dbo].[InsertSefaresh]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertSefaresh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertSefaresh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertSefaresh]
	@datatable1 tbl1 readonly,	
	@ShomareSefareshEdit bigint,
	@dateSefaresh int,
	@ShomareSefaresh bigint outPut,
	@result nvarchar(10) output
as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin
	declare @maxShomare bigint	
	if @ShomareSefareshEdit>0 --برای حالت ویرایش
		begin
			delete tblSefaresh where fldShomareSefaresh=@ShomareSefareshEdit
			set @maxShomare =@ShomareSefareshEdit
		end

	if @ShomareSefareshEdit=0 --جدید
		--select max(fldShomareSefaresh) as maxnumber from tblSefaresh
		begin
			set @maxShomare =(SELECT COALESCE(MAX(fldShomareSefaresh), 0) AS MaxSefaresh FROM tblSefaresh)
			set @maxShomare =@maxShomare+1			
		end



	INSERT INTO tblSefaresh
					(fldShomareSefaresh, fldCodeKala, fldTedadejoz,fldDate)
					select  @maxShomare, CONVERT(bigint, fld1),CONVERT(dec, fld2),@dateSefaresh output from @datatable1

			set @ShomareSefaresh =@maxShomare
			set @result ='ok'
	
end
GO

-- ===============================================
-- SP: [dbo].[InsertShomareFish]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertShomareFish', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertShomareFish] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[InsertTanzimatNew]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertTanzimatNew', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertTanzimatNew] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertTanzimatNew]

	@Name1 nvarChar(30),
	@Meghdar nvarChar(100),
	@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

-- ===============================================
-- SP: [dbo].[InsertTanzimatUser]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertTanzimatUser', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertTanzimatUser] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertTanzimatUser]
	@User bigint,
	@fldSharh nvarChar(100),
	@Meghdar nvarChar(30),
	@NoeKhata nvarchar(30) output ,
	@IDOutPut int outPut
as 

begin
	begin transaction transact
		begin try
			delete tblTanzimateuser where fldSharh=@fldSharh and fldUser=@user
			insert into tblTanzimateuser 
					 (fldSharh,fldMeghdar,fldUser)
				values(@fldSharh,@Meghdar,@User)	
			set @IDOutPut=@@IDENTITY
			set @noekhata='insert'
		commit transaction
		end try

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

-- ===============================================
-- SP: [dbo].[InsertTarheTakhfif]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertTarheTakhfif', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertTarheTakhfif] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertTarheTakhfif]

@ID bigint,
@fldMablagh decimal,
@fldDarsad decimal(18,2),
@countRow bigint

as 

begin

	insert into tblTarheTakhfif 
		values(@ID,@fldMablagh,@fldDarsad,@countRow)

end
GO

-- ===============================================
-- SP: [dbo].[InsertTarheTakhfifeRadifi]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertTarheTakhfifeRadifi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertTarheTakhfifeRadifi] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertTarheTakhfifeRadifi]

@ID bigint,
@fldMablagh decimal,
@fldDarsad decimal(18,2),
@countRow bigint

as 

begin

	insert into tblTarheTakhfifeRadifi
		values(@ID,@fldMablagh,@fldDarsad,@countRow)

end
GO

-- ===============================================
-- SP: [dbo].[inserttblPorsantVisitor]
-- ===============================================
IF OBJECT_ID(N'dbo.inserttblPorsantVisitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[inserttblPorsantVisitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[inserttblPorsantVisitor]

@ID bigint,
@fldCodeVisitor bigint,
@fldRadif bigint,
@fldMablagh decimal,
@fldDarsad decimal(18,2)


as 

begin

	insert into tblPorsantVisitor 
		values(@ID,@fldCodeVisitor,@fldRadif,@fldMablagh,@fldDarsad)

end
GO

-- ===============================================
-- SP: [dbo].[inserttest]
-- ===============================================
IF OBJECT_ID(N'dbo.inserttest', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[inserttest] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[InsertUser]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertUser', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertUser] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[InsertVahed]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertVahed', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertVahed] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[InsertVahed]

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

begin

	insert into tblVahed  (fldNameVahed)
		values(@NameVahed)	
	set @IDOutPut=@@IDENTITY
end
GO

-- ===============================================
-- SP: [dbo].[InsertVisitor]
-- ===============================================
IF OBJECT_ID(N'dbo.InsertVisitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[InsertVisitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[InsertVisitor]
@NameVisitor nvarchar(50),
@CodeSuperVisor nvarchar(50),
@DarsadePoorsant nvarchar(50),
@NoeMohasebe nvarchar(50),
@intCode int output,
@idSabt int output,
@lngCodeTafsiliCreated bigint output
as
begin
	
		execute Insert_Tbl_Tafzili_final '', @NameVisitor, '0', '', 0,'', '', '',
		'', '', '','',
		'',0,'','',
		0, 0, 0,'',
		2, @DarsadePoorsant, @CodeSuperVisor, @NoeMohasebe, @idSabt output, @lngCodeTafsiliCreated output, @intCode output

end
GO

-- ===============================================
-- SP: [dbo].[IsArchiveShomaredaryaft]
-- ===============================================
IF OBJECT_ID(N'dbo.IsArchiveShomaredaryaft', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[IsArchiveShomaredaryaft] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[IsArchiveShomarePardakht]
-- ===============================================
IF OBJECT_ID(N'dbo.IsArchiveShomarePardakht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[IsArchiveShomarePardakht] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[IsArchiveShomareSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.IsArchiveShomareSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[IsArchiveShomareSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[IsArchiveShomareVam]
-- ===============================================
IF OBJECT_ID(N'dbo.IsArchiveShomareVam', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[IsArchiveShomareVam] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[IsArchiveShomareVam]
@ShomareVam bigint,
@Result nvarchar(20) output

as
begin
	declare @lngCount bigint,@strType nvarchar(50)

	set @lngCount=(Select count(fldShomareVam) from tblVamInfo Where fldShomareVam=@ShomareVam)
	if @lngCount>0 
		begin
			set @Result='archive'
		end
	else
		begin
			set @Result='notarchive'
		end
end
GO

-- ===============================================
-- SP: [dbo].[IsArshiveShomarePas]
-- ===============================================
IF OBJECT_ID(N'dbo.IsArshiveShomarePas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[IsArshiveShomarePas] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ISTekrariCheckeDaryafti]
-- ===============================================
IF OBJECT_ID(N'dbo.ISTekrariCheckeDaryafti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ISTekrariCheckeDaryafti] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ISTekrariCheckeDaryafti]
@intShomareCheck nvarchar(30),
@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

-- ===============================================
-- SP: [dbo].[ISTekrariCheckePardakhti]
-- ===============================================
IF OBJECT_ID(N'dbo.ISTekrariCheckePardakhti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ISTekrariCheckePardakhti] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ISTekrariCheckeSayadiDaryafti]
-- ===============================================
IF OBJECT_ID(N'dbo.ISTekrariCheckeSayadiDaryafti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ISTekrariCheckeSayadiDaryafti] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ISTekrariCheckeSayadiDaryafti]
@ShomareSayad nvarchar(40),
@ID Int,
@intOutPut int output 
as

begin
	declare @RowCount int
	if @ID>0 --برای حالتی که مقایسه در حالت ویرایشه یعنی مقایسه بغیر خودش  
		begin
			set @RowCount=(Select count(fldSayad) from tblCheckeDaryafti Where fldSayad=@ShomareSayad and ID<>@ID);			
		end
	else -- برای حالتی که مقایسه در حالت درج جدیده یعنی با کل رکوردها مقایسه انجام میشه
		begin
			set @RowCount=(Select count(fldSayad) from tblCheckeDaryafti Where fldSayad=@ShomareSayad );			
		end
	
	set @intOutPut=@Rowcount

end
GO

-- ===============================================
-- SP: [dbo].[isTekrariDasteCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.isTekrariDasteCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[isTekrariDasteCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[Kardeks]
-- ===============================================
IF OBJECT_ID(N'dbo.Kardeks', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Kardeks] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Kardeks]

--@mm nvarchar(10),
--@nn nvarchar(10)

as
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END

begin
 

create table #TempMojoodieAnbar5(

fldGroupName nvarchar(50)  COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100)  COLLATE Persian_100_CI_AS,
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)  COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100)  COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100)  COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20)  COLLATE Persian_100_CI_AS
)



--insert into #TempMojoodieAnbar5 (
--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 #TempMojoodieAnbar5
                         (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 #TempMojoodieAnbar5
                         (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       #TempMojoodieAnbar5
SET                fldCodeGroup = tblKala.fldCodeGroup, fldNameKala = tblKala.fldNameKala, fldNogheSefaresh = tblKala.fldNogheSefaresh,fldTedadDarKarton=tblKala.fldTedadJoz
FROM            tblKala INNER JOIN
                         #TempMojoodieAnbar5 ON tblKala.fldCodeKala = #TempMojoodieAnbar5.fldCodeKala


UPDATE       #TempMojoodieAnbar5
SET                #TempMojoodieAnbar5.fldGroupName = tblGroupKala.fldGroupName
FROM            tblGroupKala INNER JOIN
                         #TempMojoodieAnbar5 ON #TempMojoodieAnbar5.fldCodeGroup = tblGroupKala.fldGroupId


UPDATE       #TempMojoodieAnbar5
SET                fldNameAnbar = tblAnbar.fldNameAnbar
FROM            tblAnbar INNER JOIN
                         #TempMojoodieAnbar5 ON tblAnbar.fldCode = #TempMojoodieAnbar5.fldCodeAnbar


update #TempMojoodieAnbar5 set #TempMojoodieAnbar5.fldNameVahed=tbl2.fldNameVahed,#TempMojoodieAnbar5.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=#TempMojoodieAnbar5.fldCodeKala

delete  from #TempMojoodieAnbar5  where fldCodeKala<>11001
Select * from #TempMojoodieAnbar5 
end
GO

-- ===============================================
-- SP: [dbo].[Kardeks2]
-- ===============================================
IF OBJECT_ID(N'dbo.Kardeks2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Kardeks2] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[Kardeks2]
	-- Add the parameters for the stored procedure here
	@Codekala bigint,
	@ListCodeAnbar varchar(5000)=null,
	@DateFrom varchar(8),
	@DateTo varchar(8)
	--@CodeTa bigint,
	--@GroupAz bigint,
	--@GroupTa bigInt,
	--@Type nvarchar(10)
AS
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
BEGIN
	
	Create table #TempKardeks(
		[ID] bigint,
		[fldCodeTafsili] bigint,
		[CodeKala] bigint null,
		[NameKala] nvarchar(100) collate Persian_100_CI_AS,
		[CodeGroup] bigint,
		[NameGroup] nvarchar(80) collate Persian_100_CI_AS,
		[fldShomareFactor] bigint,
		[fldShomareEnteghal] bigint,
		[fldShomareSanad] bigint,
		[fldDate] bigint,
		[fldDateShow] nvarchar(25),
		[fldSharh] nvarchar(200) collate Persian_100_CI_AS,
		[fldCodeAnbar] bigint,
		[fldNameAnbar] nvarchar(50) collate Persian_100_CI_AS,
		[fldFeeJoz] bigint,
		[fldFeeYekKarton] bigint,
		[fldMablaghKol] bigint,
		[fldTedadeJozVorood] decimal(18,2),
		[fldTedadeJozVoroodT] nvarchar(30),
		[fldTedadeJozKhorooj] decimal(18,2),
		[fldTedadeJozKhoroojT] nvarchar(30),
		[fldTedadDarKartonShow] nvarchar(100) collate Persian_100_CI_AS,
		[SumMandeJoz] decimal(18,2),
		[SumMandeJozT] nvarchar(100),
		[fldTedadDarKarton] bigint,
		[fldJozMande] bigint,
		[fldTedadVoroodKartonShow] nvarchar(100) collate Persian_100_CI_AS,
		[fldTedadKhoroojKartonShow] nvarchar(100) collate Persian_100_CI_AS,
		[fldKolMande] nvarchar(100) collate Persian_100_CI_AS,
		[fldtype] nvarchar(20) collate Persian_100_CI_AS,
		[fldtypeShow] nvarchar(40) collate Persian_100_CI_AS,
		[fldNameVahed] NVarchar(100) collate Persian_100_CI_AS,
		[fldNameVahed2] Nvarchar(100) collate Persian_100_CI_AS,
		[ConditionSum] bigint,
		[IdOrder] bigint,
		[fldRadif] bigint
	)

	--Create table #TempKardeksShow(
	--	[CodeKala] bigint null,
	--	[NameKala] nvarchar(100) collate Persian_100_CI_AS,
	--	[CodeGroup] bigint,
	--	[NameGroup] nvarchar(80) collate Persian_100_CI_AS,
	--	[fldShomareFactor] bigint,
	--	[fldShomareSanad] bigint,
	--	[fldDate] bigint,
	--	[fldSharh] nvarchar(200) collate Persian_100_CI_AS,
	--	[fldCodeAnbar] bigint,
	--	[fldNameAnbar] nvarchar(50) collate Persian_100_CI_AS,
	--	[fldFeeJoz] bigint,
	--	[fldFeeYekKarton] bigint,
	--	[fldMablaghKol] bigint,
	--	[fldTedadeJozVorood] bigint,
	--	[fldTedadeJozKhorooj] bigint,
	--	[fldTedadDarKarton] bigint,
	--	[fldJozMande] bigint,
	--	[fldTedadVoroodKartonShow] nvarchar(100) collate Persian_100_CI_AS,
	--	[fldKolKhorooj] nvarchar(100) collate Persian_100_CI_AS,
	--	[fldKolMande] nvarchar(100) collate Persian_100_CI_AS,
	--	[fldtype] nvarchar(20) collate Persian_100_CI_AS,
	--	[fldNameVahed] NVarchar(100) collate Persian_100_CI_AS,
	--	[fldNameVahed2] Nvarchar(100) collate Persian_100_CI_AS
	--)

	declare @SumMandeGhablVorood bigint,@SumGhablKhorooj bigint,@SumTedad bigint





	insert into #TempKardeks
 	 (id,fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
Select id,fldCodeTafsili,fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldTedadJoz,0,-1,'','','',fldtype,'namevahed','namevahed2' from tblRizeKharid
	where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo

	insert into #TempKardeks
 	 (fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select 0,fldCodeKala,'NameKala',-1,'namegroup',fldShomareTolid,0,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldTedadJozNahaei,0,-1,'','','',fldtype,'namevahed','namevahed2' from tblRizeTolid
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo and fldType='mahsool'




	--insert into #TempKardeks
	--	(CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
	--	Select fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldTedadJoz,0,-1,'kolvorood','kolkhorooj','kolmande','kharid','namevahed','namevahed2' from tblRizeKharid


	insert into #TempKardeks
		(fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select fldCodeTafsili, fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldTedadJoz,0,-1,'','','','bargashtazforoosh','namevahed','namevahed2' from tblRizeBargashtAzForoosh
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo


	insert into #TempKardeks
		(id,fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2,fldRadif)
		Select id,fldCodeTafsili,fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,0,fldTedadJoz,-1,'','','',fldtype,'namevahed','namevahed2',fldRadif from tblRizeForoosh
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo
		
	insert into #TempKardeks
		(fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select 0,fldCodeKala,'NameKala',-1,'namegroup',fldShomareTolid,0,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,0,fldTedadJozAvalie,-1,'','','',fldtype,'namevahed','namevahed2' from tblRizeTolid
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo and fldType='avalie'


	insert into #TempKardeks
		(fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select fldCodeTafsili,fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,0,fldTedadJoz,-1,'','','','bargashtazkharid','namevahed','namevahed2' from tblRizeBargashtAzKharid
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo
	--Select * from #TempKardeks



--	--مانده قبل

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeKharid where fldCodeKala=@Codekala and fldDate < @DateFrom and fldCodeAnbar  )	
--	if isnumeric(@SumTedad)=1
--		set @SumMandeGhablVorood=@SumTedad

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeBargashtAzForoosh where fldCodeKala=@Codekala and fldDate < @DateFrom  )	
--		if isnumeric(@SumTedad)=1
--			set @SumMandeGhablVorood=@SumTedad

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeForoosh where fldCodeKala=@Codekala and fldDate < @DateFrom  )	
--		if isnumeric(@SumTedad)=1
--			set @SumGhablKhorooj=@SumTedad

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeBargashtAzKharid where fldCodeKala=@Codekala and fldDate < @DateFrom  )	
--		if isnumeric(@SumTedad)=1
--			set @SumGhablKhorooj=@SumTedad
--insert into #TempKardeks
--		(fldCodeTafsili,fldShomareFactor,fldShomareSanad,fldSharh,fldCodeAnbar,fldNameAnbar,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
--		(0,0,0,'نقل مانده',
----####################
	

	if @ListCodeAnbar <>''
		begin
		declare @StrDeleteAnbar varchar(5000)
		set  @StrDeleteAnbar='delete from #TempKardeks 
		    where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
			execute(@StrDeleteAnbar)
		end

	UPDATE       #TempKardeks
		SET                CodeGroup = tblKala.fldCodeGroup, NameKala = tblKala.fldNameKala,fldTedadDarKarton=tblKala.fldTedadJoz
		FROM            tblKala INNER JOIN
								 #TempKardeks ON tblKala.fldCodeKala = #TempKardeks.CodeKala


	UPDATE       #TempKardeks
		SET                #TempKardeks.NameGroup = tblGroupKala.fldGroupName
		FROM            tblGroupKala INNER JOIN
								 #TempKardeks ON #TempKardeks.CodeGroup = tblGroupKala.fldGroupId


UPDATE       #TempKardeks
	SET                fldNameAnbar = tblAnbar.fldNameAnbar
	FROM            tblAnbar INNER JOIN
							 #TempKardeks ON tblAnbar.fldCode = #TempKardeks.fldCodeAnbar




update #TempKardeks set #TempKardeks.fldNameVahed=tbl2.fldNameVahed,#TempKardeks.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=#TempKardeks.CodeKala

update #TempKardeks set fldNameVahed2='' where fldTedadDarKarton=0

update #TempKardeks set fldSharh='' Where fldSharh='Sharh'

--برای جمع ستونها مجبور شدم این کار رو بکنم
update #TempKardeks set ConditionSum=1

----##########
--update #TempKardeks set IdOrder=1 where fldType='kharid'
--update #TempKardeks set IdOrder=2 where fldType='bargashtazforoosh'

----##########
    --declare @EmpCodeTafzili nvarchar(10),@SumJam bigint    
    --declare EmpCursor Cursor For
    --        Select fldCodetafzili from #TempKardeks  With (NoLock) 
    --    		open EmpCursor
    --    		fetch Next From EmpCursor into @EmpCodeTafzili
    --    		While @@Fetch_Status = 0
    --    			Begin	
    --    				set @SumJam=Select SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) from  #TempKardeks   where fldCodetafzili =@EmpCodeTafzili
    --    				update #TempKardeks  set  SumMandeJoz=(Select top(1)  fldShomare from tblDaftarcheTell Where fldCodetafzili=@EmpCodeTafzili)
    --    						where fldCodetafzili =@EmpCodeTafzili
    --    				Fetch Next from EmpCursor
    --    			into @EmpCodeTafzili
    --    		end
    --    Close EmpCurSor
    --Deallocate EmpCursor
--update  #TempKardeks set SumMandeJoz = tbl3.RunningTotal from
--	(Select fldShomareSanad,SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) OVER (PARTITION BY ConditionSum   ) AS RunningTotal from #TempKardeks) as tbl3
--	where #TempKardeks.fldShomareSanad=tbl3.fldShomareSanad

--update  #TempKardeks set SumMandeJoz = tblS.b from
--SELECT     fldShomareSanad, fldTedadeJozVorood-fldTedadeJozKhorooj,
--              (SELECT     SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) AS Expr1
--                 FROM         #TempKardeks AS b
--                 WHERE     (fldShomareSanad <= a.fldShomareSanad)) AS b
--FROM         #TempKardeks AS a


--update set      fld1, fld2,
--          (SELECT     SUM(fld2) AS Expr1
--             FROM         tblTest7 AS b
--             WHERE     (fld1 <= a.fld1)) AS b
--FROM         tblTest7 AS a


--UPDATE    #TempKardeks
--SET              SumMandeJoz = tblss.b
--FROM         (SELECT      fldShomareSanad, fldTedadeJozVorood-fldTedadeJozKhorooj,
--                                                  (SELECT     SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) AS Expr1
--                                                     FROM         #TempKardeks AS b
--                                                     WHERE     (CONVERT(dec, fldShomareSanad) <= CONVERT(dec, a.fldShomareSanad))) AS b
--                        FROM         #TempKardeks AS a) AS tblss INNER JOIN
--                      #TempKardeks ON tblss.fldShomareSanad = #TempKardeks.fldShomareSanad
--where #TempKardeks.fldShomareSanad=tbls.fldShomareSanad 

update #TempKardeks set IdOrder=convert(bigint, Convert(varchar,fldDate) + convert(varchar, fldShomareSanad))
update #TempKardeks set IdOrder=convert(varchar,IdOrder) + Convert(varchar,fldShomareEnteghal) where fldtype='enteghal'
update #TempKardeks set IdOrder=convert(varchar,IdOrder) + '1' where len(IdOrder)=9 and fldTedadeJozVorood>0
update #TempKardeks set IdOrder=convert(varchar,IdOrder) + '2' where len(IdOrder)=9 and fldTedadeJozKhorooj>0


---جمع ورود و خروج
UPDATE    #TempKardeks
SET              SumMandeJoz = tblss.b
FROM         (SELECT     44 AS Expr1, IdOrder, fldTedadeJozVorood - fldTedadeJozKhorooj AS Expr2,
                                                  (SELECT     SUM(fldTedadeJozVorood - fldTedadeJozKhorooj) AS Expr1
                                                     FROM         #TempKardeks AS b
                                                     WHERE     (CONVERT(varchar, IdOrder) <= CONVERT(varchar, a.IdOrder))) AS b
                        FROM         #TempKardeks AS a) AS tblss INNER JOIN
                      #TempKardeks ON tblss.IdOrder = #TempKardeks.IdOrder
        

update #TempKardeks set SumMandeJozT=SumMandeJoz,fldTedadeJozVoroodT=fldTedadeJozVorood,fldTedadeJozKhoroojT=fldTedadeJozKhorooj
update #TempKardeks set SumMandeJozT=LEFT(Convert(varchar,SumMandeJoz),len(Convert(varchar,SumMandeJoz))-3) where right(convert(varchar,SumMandeJoz),2)='00'
update #TempKardeks set fldTedadeJozVoroodT=LEFT(Convert(varchar,fldTedadeJozVorood),len(Convert(varchar,fldTedadeJozVorood))-3) where right(convert(varchar,fldTedadeJozVorood),2)='00'
update #TempKardeks set fldTedadeJozKhoroojT=LEFT(Convert(varchar,fldTedadeJozKhorooj),len(Convert(varchar,fldTedadeJozKhorooj))-3) where right(convert(varchar,fldTedadeJozKhorooj),2)='00'
              

update #TempKardeks Set fldTedadVoroodKartonShow=Convert(varchar,floor(fldTedadeJozVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,fldTedadeJozVorood), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempKardeks Set fldTedadKhoroojKartonShow=Convert(varchar,floor(fldTedadeJozKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,fldTedadeJozKhorooj), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempKardeks Set fldKolMande=Convert(varchar,floor(SumMandeJoz / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,SumMandeJoz), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempKardeks Set fldTedadVoroodKartonShow='' where fldTedadeJozVorood=0
update #TempKardeks Set fldTedadKhoroojKartonShow='' where fldTedadeJozKhorooj=0



--update #TempKardeks Set fldTedadKhoroojKartonShow=Convert(varchar,floor(fldTedadeJozKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldTedadeJozKhorooj, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--	where fldTedadDarKarton>0

--جمع ستونها
--SELECT
--  AccountNumber,
--  flddate,
--  bill,
--  SUM(bill) OVER (PARTITION BY AccountNumber ORDER BY flddate) AS RunningTotal
--FROM
--  dbo.Table1 


----فیلتر تا قبل از تاریخ 
--Insert into #TempKardeksShow
--	(fldTedadeJozVorood,fldTedadeJozKhorooj,fldTedadDarKarton, NameGroup, CodeGroup, CodeKala, NameKala, fldNameVahed, fldNameVahed2)
--SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, 
--                         fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0
--FROM            #TempKardeks
--GROUP BY CodeKala, NameGroup, CodeGroup, NameKala, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol




	--Select CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2
	--	from #TempKardeks
	--update 

	--Select fldTedadeJozVorood,fldTedadeJozKhorooj,fldDate,fldShomareSanad,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldTedadDarKartonShow,SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) OVER (PARTITION BY ConditionSum ORDER BY fldDate,fldShomareSanad) AS RunningTotal from #TempKardeks
	update #TempKardeks set fldTypeShow='خرید' where fldType='kharid'
	update #TempKardeks set fldTypeShow='ابتدای دوره' where fldType='mojodi_ebteda_doreh'	
	update #TempKardeks set fldTypeShow='انتقال بین انبار' where fldType='enteghal'
	update #TempKardeks set fldTypeShow='فروش' where fldType='foroosh'
	update #TempKardeks set fldTypeShow='برگشت از فروش' where fldType='bargashtazforoosh'
	update #TempKardeks set fldTypeShow='برگشت از خرید' where fldType='bargashtazkharid'
	update #TempKardeks set fldTypeShow='تبدیل به محصول نهایی' where fldType='avalie'
	update #TempKardeks set fldTypeShow='محصول تولید شده در فرایند تولید' where fldType='mahsool'
	update #TempKardeks set fldTypeShow='مغایرت',fldCodeTafsili=0,fldSharh='مغایرت' where fldType='Moghayrat'

	
	update #TempKardeks set fldShomareFactor=fldShomareEnteghal where fldType='enteghal'

	update #TempKardeks set fldSharh= tblTafzili.fldSharheTafzili + ' ' + fldSharh from tblTafzili 
		Where #TempKardeks.fldCodeTafsili=tblTafzili.fldCodeTafzili

	
	update #TempKardeks set flddateshow =substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2)
	Select  ROW_NUMBER() OVER(ORDER BY flddate,fldshomaresanad ) AS Row,id,fldSharh,fldtypeShow,fldShomareFactor,flddateshow,fldTedadeJozVoroodT As fldTedadeJozVorood,fldTedadeJozKhoroojT as fldTedadeJozKhorooj,SumMandeJozT as SumMandeJoz,fldNameVahed,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldTedadDarKarton,fldNameVahed2,fldKolMande,fldShomareSanad,fldNameAnbar,fldDate,fldtype,fldRadif from #TempKardeks order by Convert(varchar,IdOrder)
	
--FROM
--  dbo.Table1 

END
GO

-- ===============================================
-- SP: [dbo].[Kardeks3]
-- ===============================================
IF OBJECT_ID(N'dbo.Kardeks3', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Kardeks3] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[Kardeks3]
	-- Add the parameters for the stored procedure here
	@Codekala bigint,
	@ListCodeAnbar varchar(5000)=null,
	@DateFrom varchar(8),
	@DateTo varchar(8)
	--@CodeTa bigint,
	--@GroupAz bigint,
	--@GroupTa bigInt,
	--@Type nvarchar(10)
AS
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
BEGIN
	
	Create table #TempKardeks(
		[ID] bigint,
		[fldCodeTafsili] bigint,
		[CodeKala] bigint null,
		[NameKala] nvarchar(100) collate Persian_100_CI_AS,
		[CodeGroup] bigint,
		[NameGroup] nvarchar(80) collate Persian_100_CI_AS,
		[fldShomareFactor] bigint,
		[fldShomareEnteghal] bigint,
		[fldShomareSanad] bigint,
		[fldDate] bigint,
		[fldDateShow] nvarchar(25),
		[fldSharh] nvarchar(200) collate Persian_100_CI_AS,
		[fldCodeAnbar] bigint,
		[fldNameAnbar] nvarchar(50) collate Persian_100_CI_AS,
		[fldFeeJoz] bigint,
		[fldFeeYekKarton] bigint,
		[fldMablaghKol] bigint,

		[fldMablaghTakhfif] decimal(18,2),
		[fldFeeVahed1BadAzTakhfif] decimal(18,2),
		[fldFeeVahed2BadAzTakhfif] decimal(18,2),
		[fldArzeshAfzode]  decimal(18,2),
		[fldFeeKolBadAzTakhfif]  decimal(18,2),
		[fldMablaghKhales]  decimal(18,2),

		[fldTedadeJozVorood] decimal(18,2),
		[fldTedadeJozVoroodT] nvarchar(30),
		[fldTedadeJozKhorooj] decimal(18,2),
		[fldTedadeJozKhoroojT] nvarchar(30),
		[fldTedadDarKartonShow] nvarchar(100) collate Persian_100_CI_AS,
		[SumMandeJoz] decimal(18,2),
		[SumMandeJozT] nvarchar(100),
		[fldTedadDarKarton] bigint,
		[fldJozMande] bigint,
		[fldTedadVoroodKartonShow] nvarchar(100) collate Persian_100_CI_AS,
		[fldTedadKhoroojKartonShow] nvarchar(100) collate Persian_100_CI_AS,
		[fldKolMande] nvarchar(100) collate Persian_100_CI_AS,
		[fldtype] nvarchar(20) collate Persian_100_CI_AS,
		[fldtypeShow] nvarchar(40) collate Persian_100_CI_AS,
		[fldNameVahed] NVarchar(100) collate Persian_100_CI_AS,
		[fldNameVahed2] Nvarchar(100) collate Persian_100_CI_AS,
		[ConditionSum] bigint,
		[IdOrder] bigint,
		[fldRadif] bigint
	)

	--Create table #TempKardeksShow(
	--	[CodeKala] bigint null,
	--	[NameKala] nvarchar(100) collate Persian_100_CI_AS,
	--	[CodeGroup] bigint,
	--	[NameGroup] nvarchar(80) collate Persian_100_CI_AS,
	--	[fldShomareFactor] bigint,
	--	[fldShomareSanad] bigint,
	--	[fldDate] bigint,
	--	[fldSharh] nvarchar(200) collate Persian_100_CI_AS,
	--	[fldCodeAnbar] bigint,
	--	[fldNameAnbar] nvarchar(50) collate Persian_100_CI_AS,
	--	[fldFeeJoz] bigint,
	--	[fldFeeYekKarton] bigint,
	--	[fldMablaghKol] bigint,
	--	[fldTedadeJozVorood] bigint,
	--	[fldTedadeJozKhorooj] bigint,
	--	[fldTedadDarKarton] bigint,
	--	[fldJozMande] bigint,
	--	[fldTedadVoroodKartonShow] nvarchar(100) collate Persian_100_CI_AS,
	--	[fldKolKhorooj] nvarchar(100) collate Persian_100_CI_AS,
	--	[fldKolMande] nvarchar(100) collate Persian_100_CI_AS,
	--	[fldtype] nvarchar(20) collate Persian_100_CI_AS,
	--	[fldNameVahed] NVarchar(100) collate Persian_100_CI_AS,
	--	[fldNameVahed2] Nvarchar(100) collate Persian_100_CI_AS
	--)

	declare @SumMandeGhablVorood bigint,@SumGhablKhorooj bigint,@SumTedad bigint





	insert into #TempKardeks
 	 (id,fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
Select id,fldCodeTafsili,fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldTedadJoz,0,-1,'','','',fldtype,'namevahed','namevahed2' from tblRizeKharid
	where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo

	insert into #TempKardeks
 	 (fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select 0,fldCodeKala,'NameKala',-1,'namegroup',fldShomareTolid,0,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,0,fldFeeJoz,fldFeeYekCarton,0,fldMablaghKhales,fldMablaghKhales,fldTedadJozNahaei,0,-1,'','','',fldtype,'namevahed','namevahed2' from tblRizeTolid
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo and fldType='mahsool'




	--insert into #TempKardeks
	--	(CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
	--	Select fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldTedadJoz,0,-1,'kolvorood','kolkhorooj','kolmande','kharid','namevahed','namevahed2' from tblRizeKharid


	insert into #TempKardeks
		(fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select fldCodeTafsili, fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldTedadJoz,0,-1,'','','','bargashtazforoosh','namevahed','namevahed2' from tblRizeBargashtAzForoosh
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo


	insert into #TempKardeks
		(id,fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2,fldRadif)
		Select id,fldCodeTafsili,fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,0,fldTedadJoz,-1,'','','',fldtype,'namevahed','namevahed2',fldRadif from tblRizeForoosh
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo

	insert into #TempKardeks
		(id,fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2,fldRadif)
		Select id,fldCodeTafsili,fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,0,fldTedadJoz,-1,'','','',fldtype,'namevahed','namevahed2',fldRadif from tblRizHavaleHazine
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo
		
	insert into #TempKardeks
		(fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select 0,fldCodeKala,'NameKala',-1,'namegroup',fldShomareTolid,0,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,0,fldTedadJozAvalie,-1,'','','',fldtype,'namevahed','namevahed2' from tblRizeTolid
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo and fldType='avalie'


	insert into #TempKardeks
		(fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select fldCodeTafsili,fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,0,fldTedadJoz,-1,'','','',fldtype,'namevahed','namevahed2' from tblRizeBargashtAzKharid
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo
	--Select * from #TempKardeks



--	--مانده قبل

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeKharid where fldCodeKala=@Codekala and fldDate < @DateFrom and fldCodeAnbar  )	
--	if isnumeric(@SumTedad)=1
--		set @SumMandeGhablVorood=@SumTedad

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeBargashtAzForoosh where fldCodeKala=@Codekala and fldDate < @DateFrom  )	
--		if isnumeric(@SumTedad)=1
--			set @SumMandeGhablVorood=@SumTedad

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeForoosh where fldCodeKala=@Codekala and fldDate < @DateFrom  )	
--		if isnumeric(@SumTedad)=1
--			set @SumGhablKhorooj=@SumTedad

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeBargashtAzKharid where fldCodeKala=@Codekala and fldDate < @DateFrom  )	
--		if isnumeric(@SumTedad)=1
--			set @SumGhablKhorooj=@SumTedad
--insert into #TempKardeks
--		(fldCodeTafsili,fldShomareFactor,fldShomareSanad,fldSharh,fldCodeAnbar,fldNameAnbar,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
--		(0,0,0,'نقل مانده',
----####################
	

	if @ListCodeAnbar <>''
		begin
		declare @StrDeleteAnbar varchar(5000)
		set  @StrDeleteAnbar='delete from #TempKardeks 
		    where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
			execute(@StrDeleteAnbar)
		end

	UPDATE       #TempKardeks
		SET                CodeGroup = tblKala.fldCodeGroup, NameKala = tblKala.fldNameKala,fldTedadDarKarton=tblKala.fldTedadJoz
		FROM            tblKala INNER JOIN
								 #TempKardeks ON tblKala.fldCodeKala = #TempKardeks.CodeKala


	UPDATE       #TempKardeks
		SET                #TempKardeks.NameGroup = tblGroupKala.fldGroupName
		FROM            tblGroupKala INNER JOIN
								 #TempKardeks ON #TempKardeks.CodeGroup = tblGroupKala.fldGroupId


UPDATE       #TempKardeks
	SET                fldNameAnbar = tblAnbar.fldNameAnbar
	FROM            tblAnbar INNER JOIN
							 #TempKardeks ON tblAnbar.fldCode = #TempKardeks.fldCodeAnbar




update #TempKardeks set #TempKardeks.fldNameVahed=tbl2.fldNameVahed,#TempKardeks.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=#TempKardeks.CodeKala

update #TempKardeks set fldNameVahed2='' where fldTedadDarKarton=0

update #TempKardeks set fldSharh='' Where fldSharh='Sharh'

--برای جمع ستونها مجبور شدم این کار رو بکنم
update #TempKardeks set ConditionSum=1

----##########
--update #TempKardeks set IdOrder=1 where fldType='kharid'
--update #TempKardeks set IdOrder=2 where fldType='bargashtazforoosh'

----##########
    --declare @EmpCodeTafzili nvarchar(10),@SumJam bigint    
    --declare EmpCursor Cursor For
    --        Select fldCodetafzili from #TempKardeks  With (NoLock) 
    --    		open EmpCursor
    --    		fetch Next From EmpCursor into @EmpCodeTafzili
    --    		While @@Fetch_Status = 0
    --    			Begin	
    --    				set @SumJam=Select SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) from  #TempKardeks   where fldCodetafzili =@EmpCodeTafzili
    --    				update #TempKardeks  set  SumMandeJoz=(Select top(1)  fldShomare from tblDaftarcheTell Where fldCodetafzili=@EmpCodeTafzili)
    --    						where fldCodetafzili =@EmpCodeTafzili
    --    				Fetch Next from EmpCursor
    --    			into @EmpCodeTafzili
    --    		end
    --    Close EmpCurSor
    --Deallocate EmpCursor
--update  #TempKardeks set SumMandeJoz = tbl3.RunningTotal from
--	(Select fldShomareSanad,SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) OVER (PARTITION BY ConditionSum   ) AS RunningTotal from #TempKardeks) as tbl3
--	where #TempKardeks.fldShomareSanad=tbl3.fldShomareSanad

--update  #TempKardeks set SumMandeJoz = tblS.b from
--SELECT     fldShomareSanad, fldTedadeJozVorood-fldTedadeJozKhorooj,
--              (SELECT     SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) AS Expr1
--                 FROM         #TempKardeks AS b
--                 WHERE     (fldShomareSanad <= a.fldShomareSanad)) AS b
--FROM         #TempKardeks AS a


--update set      fld1, fld2,
--          (SELECT     SUM(fld2) AS Expr1
--             FROM         tblTest7 AS b
--             WHERE     (fld1 <= a.fld1)) AS b
--FROM         tblTest7 AS a


--UPDATE    #TempKardeks
--SET              SumMandeJoz = tblss.b
--FROM         (SELECT      fldShomareSanad, fldTedadeJozVorood-fldTedadeJozKhorooj,
--                                                  (SELECT     SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) AS Expr1
--                                                     FROM         #TempKardeks AS b
--                                                     WHERE     (CONVERT(dec, fldShomareSanad) <= CONVERT(dec, a.fldShomareSanad))) AS b
--                        FROM         #TempKardeks AS a) AS tblss INNER JOIN
--                      #TempKardeks ON tblss.fldShomareSanad = #TempKardeks.fldShomareSanad
--where #TempKardeks.fldShomareSanad=tbls.fldShomareSanad 

update #TempKardeks set IdOrder=convert(bigint, Convert(varchar,fldDate) + convert(varchar, fldShomareSanad))
update #TempKardeks set IdOrder=convert(varchar,IdOrder) + Convert(varchar,fldShomareEnteghal) where fldtype='enteghal'
update #TempKardeks set IdOrder=convert(varchar,IdOrder) + '1' where len(IdOrder)=9 and fldTedadeJozVorood>0
update #TempKardeks set IdOrder=convert(varchar,IdOrder) + '2' where len(IdOrder)=9 and fldTedadeJozKhorooj>0


---جمع ورود و خروج
UPDATE    #TempKardeks
SET              SumMandeJoz = tblss.b
FROM         (SELECT     44 AS Expr1, IdOrder, fldTedadeJozVorood - fldTedadeJozKhorooj AS Expr2,
                                                  (SELECT     SUM(fldTedadeJozVorood - fldTedadeJozKhorooj) AS Expr1
                                                     FROM         #TempKardeks AS b
                                                     WHERE     (CONVERT(varchar, IdOrder) <= CONVERT(varchar, a.IdOrder))) AS b
                        FROM         #TempKardeks AS a) AS tblss INNER JOIN
                      #TempKardeks ON tblss.IdOrder = #TempKardeks.IdOrder
        

update #TempKardeks set SumMandeJozT=SumMandeJoz,fldTedadeJozVoroodT=fldTedadeJozVorood,fldTedadeJozKhoroojT=fldTedadeJozKhorooj
update #TempKardeks set SumMandeJozT=LEFT(Convert(varchar,SumMandeJoz),len(Convert(varchar,SumMandeJoz))-3) where right(convert(varchar,SumMandeJoz),2)='00'
update #TempKardeks set fldTedadeJozVoroodT=LEFT(Convert(varchar,fldTedadeJozVorood),len(Convert(varchar,fldTedadeJozVorood))-3) where right(convert(varchar,fldTedadeJozVorood),2)='00'
update #TempKardeks set fldTedadeJozKhoroojT=LEFT(Convert(varchar,fldTedadeJozKhorooj),len(Convert(varchar,fldTedadeJozKhorooj))-3) where right(convert(varchar,fldTedadeJozKhorooj),2)='00'
              

update #TempKardeks Set fldTedadVoroodKartonShow=Convert(varchar,floor(fldTedadeJozVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,fldTedadeJozVorood), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempKardeks Set fldTedadKhoroojKartonShow=Convert(varchar,floor(fldTedadeJozKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,fldTedadeJozKhorooj), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0


update #TempKardeks Set fldKolMande=convert(varchar,(-1)*Convert(varchar,floor((-1)*convert(dec,SumMandeJoz) / convert(dec,fldTedadDarKarton)))) + ' کل ' +  Convert(varchar, { fn MOD(Convert(dec, SumMandeJoz), convert(dec,fldTedadDarKarton)) } )  +  ' جز '--convert(varchar,SumMandeJoz)--Convert(varchar,floor(SumMandeJoz / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,SumMandeJoz), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where SumMandeJoz<0 and fldTedadDarKarton>0


update #TempKardeks Set fldTedadVoroodKartonShow='' where fldTedadeJozVorood=0
update #TempKardeks Set fldTedadKhoroojKartonShow='' where fldTedadeJozKhorooj=0



--update #TempKardeks Set fldTedadKhoroojKartonShow=Convert(varchar,floor(fldTedadeJozKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldTedadeJozKhorooj, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--	where fldTedadDarKarton>0

--جمع ستونها
--SELECT
--  AccountNumber,
--  flddate,
--  bill,
--  SUM(bill) OVER (PARTITION BY AccountNumber ORDER BY flddate) AS RunningTotal
--FROM
--  dbo.Table1 


----فیلتر تا قبل از تاریخ 
--Insert into #TempKardeksShow
--	(fldTedadeJozVorood,fldTedadeJozKhorooj,fldTedadDarKarton, NameGroup, CodeGroup, CodeKala, NameKala, fldNameVahed, fldNameVahed2)
--SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, 
--                         fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0
--FROM            #TempKardeks
--GROUP BY CodeKala, NameGroup, CodeGroup, NameKala, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol




	--Select CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2
	--	from #TempKardeks
	--update 

	--Select fldTedadeJozVorood,fldTedadeJozKhorooj,fldDate,fldShomareSanad,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldTedadDarKartonShow,SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) OVER (PARTITION BY ConditionSum ORDER BY fldDate,fldShomareSanad) AS RunningTotal from #TempKardeks
	update #TempKardeks set fldTypeShow='خرید' where fldType='kharid'
	update #TempKardeks set fldTypeShow='امانی' where fldType='amani'
	update #TempKardeks set fldTypeShow='برگشت امانی' where fldType='bargashtamani'
	update #TempKardeks set fldTypeShow='ابتدای دوره' where fldType='mojodi_ebteda_doreh'	
	update #TempKardeks set fldTypeShow='انتقال بین انبار' where fldType='enteghal'
	update #TempKardeks set fldTypeShow='حواله خروج' where fldType='havalekhorooj'
	update #TempKardeks set fldTypeShow='فروش' where fldType='foroosh'
	update #TempKardeks set fldTypeShow='برگشت از فروش' where fldType='bargashtazforoosh'
	update #TempKardeks set fldTypeShow='برگشت از خرید' where fldType='bargashtazkharid'
	update #TempKardeks set fldTypeShow='تبدیل به محصول نهایی' where fldType='avalie'
	update #TempKardeks set fldTypeShow='محصول تولید شده در فرایند تولید' where fldType='mahsool'
	update #TempKardeks set fldTypeShow='مغایرت',fldCodeTafsili=0,fldSharh='مغایرت' where fldType='Moghayrat'

	
	update #TempKardeks set fldShomareFactor=fldShomareEnteghal where fldType='enteghal'

	update #TempKardeks set fldSharh= tblTafzili.fldSharheTafzili + ' ' + fldSharh from tblTafzili 
		Where #TempKardeks.fldCodeTafsili=tblTafzili.fldCodeTafzili

	update #TempKardeks Set fldKolMande=Convert(varchar,floor(summandejoz / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec, summandejoz), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

	update #TempKardeks set flddateshow =substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2)
	Select  ROW_NUMBER() OVER(ORDER BY flddate,fldshomaresanad ) AS Row,fldSharh,fldtypeShow,fldShomareFactor,flddateshow,fldTedadeJozVoroodT As fldTedadeJozVorood,fldTedadeJozKhoroojT as fldTedadeJozKhorooj,SumMandeJozT as SumMandeJoz,fldNameVahed,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldFeeKolBadAzTakhfif,fldArzeshAfzode,fldMablaghKhales,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldTedadDarKarton,fldNameVahed2,fldKolMande,fldShomareSanad,fldNameAnbar,fldDate,fldtype,fldRadif,id from #TempKardeks order by Convert(varchar,IdOrder)
	
--FROM
--  dbo.Table1 

END
GO

-- ===============================================
-- SP: [dbo].[KardeksForSood]
-- ===============================================
IF OBJECT_ID(N'dbo.KardeksForSood', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KardeksForSood] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[KardeksForSood]
	-- Add the parameters for the stored procedure here
	@Codekala bigint,
	@ListCodeAnbar varchar(5000)=null,
	@DateFrom varchar(8),
	@DateTo varchar(8)
	--@CodeTa bigint,
	--@GroupAz bigint,
	--@GroupTa bigInt,
	--@Type nvarchar(10)
AS
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
BEGIN
	
	Create table #TempKardeks(
		[ID] bigint,
		[fldCodeTafsili] bigint,
		[CodeKala] bigint null,
		[NameKala] nvarchar(100) collate Persian_100_CI_AS,
		[CodeGroup] bigint,
		[NameGroup] nvarchar(80) collate Persian_100_CI_AS,
		[fldShomareFactor] bigint,
		[fldShomareEnteghal] bigint,
		[fldShomareSanad] bigint,
		[fldDate] bigint,
		[fldDateShow] nvarchar(25),
		[fldSharh] nvarchar(200) collate Persian_100_CI_AS,
		[fldCodeAnbar] bigint,
		[fldNameAnbar] nvarchar(50) collate Persian_100_CI_AS,
		[fldFeeJoz] bigint,
		[fldFeeVahed1BadAzTakhfif] bigint,
		[fldFeeYekKarton] bigint,
		[fldMablaghKol] bigint,
		[fldTedadeJozVorood] decimal(18,2),
		[fldTedadeJozVoroodT] nvarchar(20),
		[fldTedadeJozKhorooj] decimal(18,2),
		[fldTedadeJozKhoroojT] nvarchar(20),
		[fldTedadDarKartonShow] nvarchar(100) collate Persian_100_CI_AS,
		[SumMandeJoz] decimal(18,2),
		[SumMandeJozT] nvarchar(100),
		[fldTedadDarKarton] bigint,
		[fldJozMande] bigint,
		[fldTedadVoroodKartonShow] nvarchar(100) collate Persian_100_CI_AS,
		[fldTedadKhoroojKartonShow] nvarchar(100) collate Persian_100_CI_AS,
		[fldKolMande] nvarchar(100) collate Persian_100_CI_AS,
		[fldtype] nvarchar(20) collate Persian_100_CI_AS,
		[fldtypeShow] nvarchar(40) collate Persian_100_CI_AS,
		[fldNameVahed] NVarchar(100) collate Persian_100_CI_AS,
		[fldNameVahed2] Nvarchar(100) collate Persian_100_CI_AS,
		[ConditionSum] bigint,
		[IdOrder] bigint,
		[fldRadif] bigint
	)



	declare @SumMandeGhablVorood bigint,@SumGhablKhorooj bigint,@SumTedad bigint





	insert into #TempKardeks
 	 (id,fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
Select id,fldCodeTafsili,fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekCarton,fldMablaghKhales,fldTedadJoz,0,-1,'','','',fldtype,'namevahed','namevahed2' from tblRizeKharid
	where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo

	insert into #TempKardeks
 	 (fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select 0,fldCodeKala,'NameKala',-1,'namegroup',fldShomareTolid,0,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekCarton,fldFeeKol,fldTedadJozNahaei,0,-1,'','','',fldtype,'namevahed','namevahed2' from tblRizeTolid
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo and fldType='mahsool'




	--insert into #TempKardeks
	--	(CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
	--	Select fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldTedadJoz,0,-1,'kolvorood','kolkhorooj','kolmande','kharid','namevahed','namevahed2' from tblRizeKharid


	insert into #TempKardeks
		(fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select fldCodeTafsili, fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekCarton,fldMablaghKhales,fldTedadJoz,0,-1,'','','','bargashtazforoosh','namevahed','namevahed2' from tblRizeBargashtAzForoosh
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo


	insert into #TempKardeks
		(id,fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2,fldRadif)
		Select id,fldCodeTafsili,fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekCarton,fldMablaghKhales,0,fldTedadJoz,-1,'','','',fldtype,'namevahed','namevahed2',fldRadif from tblRizeForoosh
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo
		
	insert into #TempKardeks
		(fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select 0,fldCodeKala,'NameKala',-1,'namegroup',fldShomareTolid,0,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekCarton,fldFeeKol,0,fldTedadJozAvalie,-1,'','','',fldtype,'namevahed','namevahed2' from tblRizeTolid
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo and fldType='avalie'


	insert into #TempKardeks
		(fldCodeTafsili,CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
		Select fldCodeTafsili,fldCodeKala,'NameKala',-1,'namegroup',fldShomareFactor,fldShomareSanad,fldDate,'Sharh',fldCodeAnbar,'nameanbar',fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekCarton,fldMablaghKhales,0,fldTedadJoz,-1,'','','','bargashtazkharid','namevahed','namevahed2' from tblRizeBargashtAzKharid
		where fldCodeKala=@Codekala and fldDate BETWEEN  @DateFrom  AND  @DateTo
	--Select * from #TempKardeks



--	--مانده قبل

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeKharid where fldCodeKala=@Codekala and fldDate < @DateFrom and fldCodeAnbar  )	
--	if isnumeric(@SumTedad)=1
--		set @SumMandeGhablVorood=@SumTedad

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeBargashtAzForoosh where fldCodeKala=@Codekala and fldDate < @DateFrom  )	
--		if isnumeric(@SumTedad)=1
--			set @SumMandeGhablVorood=@SumTedad

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeForoosh where fldCodeKala=@Codekala and fldDate < @DateFrom  )	
--		if isnumeric(@SumTedad)=1
--			set @SumGhablKhorooj=@SumTedad

--	set @SumTedad=(Select Sum(fldTedadJoz) as SumMande from tblRizeBargashtAzKharid where fldCodeKala=@Codekala and fldDate < @DateFrom  )	
--		if isnumeric(@SumTedad)=1
--			set @SumGhablKhorooj=@SumTedad
--insert into #TempKardeks
--		(fldCodeTafsili,fldShomareFactor,fldShomareSanad,fldSharh,fldCodeAnbar,fldNameAnbar,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2)
--		(0,0,0,'نقل مانده',
----####################
	

	if @ListCodeAnbar <>''
		begin
		declare @StrDeleteAnbar varchar(5000)
		set  @StrDeleteAnbar='delete from #TempKardeks 
		    where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
			execute(@StrDeleteAnbar)
		end

	UPDATE       #TempKardeks
		SET                CodeGroup = tblKala.fldCodeGroup, NameKala = tblKala.fldNameKala,fldTedadDarKarton=tblKala.fldTedadJoz
		FROM            tblKala INNER JOIN
								 #TempKardeks ON tblKala.fldCodeKala = #TempKardeks.CodeKala


	UPDATE       #TempKardeks
		SET                #TempKardeks.NameGroup = tblGroupKala.fldGroupName
		FROM            tblGroupKala INNER JOIN
								 #TempKardeks ON #TempKardeks.CodeGroup = tblGroupKala.fldGroupId


UPDATE       #TempKardeks
	SET                fldNameAnbar = tblAnbar.fldNameAnbar
	FROM            tblAnbar INNER JOIN
							 #TempKardeks ON tblAnbar.fldCode = #TempKardeks.fldCodeAnbar




update #TempKardeks set #TempKardeks.fldNameVahed=tbl2.fldNameVahed,#TempKardeks.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=#TempKardeks.CodeKala

update #TempKardeks set fldNameVahed2='' where fldTedadDarKarton=0

update #TempKardeks set fldSharh='' Where fldSharh='Sharh'

--برای جمع ستونها مجبور شدم این کار رو بکنم
update #TempKardeks set ConditionSum=1

----##########
--update #TempKardeks set IdOrder=1 where fldType='kharid'
--update #TempKardeks set IdOrder=2 where fldType='bargashtazforoosh'

----##########
    --declare @EmpCodeTafzili nvarchar(10),@SumJam bigint    
    --declare EmpCursor Cursor For
    --        Select fldCodetafzili from #TempKardeks  With (NoLock) 
    --    		open EmpCursor
    --    		fetch Next From EmpCursor into @EmpCodeTafzili
    --    		While @@Fetch_Status = 0
    --    			Begin	
    --    				set @SumJam=Select SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) from  #TempKardeks   where fldCodetafzili =@EmpCodeTafzili
    --    				update #TempKardeks  set  SumMandeJoz=(Select top(1)  fldShomare from tblDaftarcheTell Where fldCodetafzili=@EmpCodeTafzili)
    --    						where fldCodetafzili =@EmpCodeTafzili
    --    				Fetch Next from EmpCursor
    --    			into @EmpCodeTafzili
    --    		end
    --    Close EmpCurSor
    --Deallocate EmpCursor
--update  #TempKardeks set SumMandeJoz = tbl3.RunningTotal from
--	(Select fldShomareSanad,SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) OVER (PARTITION BY ConditionSum   ) AS RunningTotal from #TempKardeks) as tbl3
--	where #TempKardeks.fldShomareSanad=tbl3.fldShomareSanad

--update  #TempKardeks set SumMandeJoz = tblS.b from
--SELECT     fldShomareSanad, fldTedadeJozVorood-fldTedadeJozKhorooj,
--              (SELECT     SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) AS Expr1
--                 FROM         #TempKardeks AS b
--                 WHERE     (fldShomareSanad <= a.fldShomareSanad)) AS b
--FROM         #TempKardeks AS a


--update set      fld1, fld2,
--          (SELECT     SUM(fld2) AS Expr1
--             FROM         tblTest7 AS b
--             WHERE     (fld1 <= a.fld1)) AS b
--FROM         tblTest7 AS a


--UPDATE    #TempKardeks
--SET              SumMandeJoz = tblss.b
--FROM         (SELECT      fldShomareSanad, fldTedadeJozVorood-fldTedadeJozKhorooj,
--                                                  (SELECT     SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) AS Expr1
--                                                     FROM         #TempKardeks AS b
--                                                     WHERE     (CONVERT(dec, fldShomareSanad) <= CONVERT(dec, a.fldShomareSanad))) AS b
--                        FROM         #TempKardeks AS a) AS tblss INNER JOIN
--                      #TempKardeks ON tblss.fldShomareSanad = #TempKardeks.fldShomareSanad
--where #TempKardeks.fldShomareSanad=tbls.fldShomareSanad 

update #TempKardeks set IdOrder=convert(bigint, Convert(varchar,fldDate) + convert(varchar, fldShomareSanad))
update #TempKardeks set IdOrder=convert(varchar,IdOrder) + fldShomareEnteghal where fldtype='enteghal'
update #TempKardeks set IdOrder=convert(varchar,IdOrder) + '1' where len(IdOrder)=9 and fldTedadeJozVorood>0
update #TempKardeks set IdOrder=convert(varchar,IdOrder) + '2' where len(IdOrder)=9 and fldTedadeJozKhorooj>0


---جمع ورود و خروج
UPDATE    #TempKardeks
SET              SumMandeJoz = tblss.b
FROM         (SELECT     44 AS Expr1, IdOrder, fldTedadeJozVorood - fldTedadeJozKhorooj AS Expr2,
                                                  (SELECT     SUM(fldTedadeJozVorood - fldTedadeJozKhorooj) AS Expr1
                                                     FROM         #TempKardeks AS b
                                                     WHERE     (CONVERT(varchar, IdOrder) <= CONVERT(varchar, a.IdOrder))) AS b
                        FROM         #TempKardeks AS a) AS tblss INNER JOIN
                      #TempKardeks ON tblss.IdOrder = #TempKardeks.IdOrder
        

update #TempKardeks set SumMandeJozT=SumMandeJoz,fldTedadeJozVoroodT=fldTedadeJozVorood,fldTedadeJozKhoroojT=fldTedadeJozKhorooj
update #TempKardeks set SumMandeJozT=LEFT(Convert(varchar,SumMandeJoz),len(Convert(varchar,SumMandeJoz))-3) where right(convert(varchar,SumMandeJoz),2)='00'
update #TempKardeks set fldTedadeJozVoroodT=LEFT(Convert(varchar,fldTedadeJozVorood),len(Convert(varchar,fldTedadeJozVorood))-3) where right(convert(varchar,fldTedadeJozVorood),2)='00'
update #TempKardeks set fldTedadeJozKhoroojT=LEFT(Convert(varchar,fldTedadeJozKhorooj),len(Convert(varchar,fldTedadeJozKhorooj))-3) where right(convert(varchar,fldTedadeJozKhorooj),2)='00'
              

update #TempKardeks Set fldTedadVoroodKartonShow=Convert(varchar,floor(fldTedadeJozVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,fldTedadeJozVorood), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempKardeks Set fldTedadKhoroojKartonShow=Convert(varchar,floor(fldTedadeJozKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,fldTedadeJozKhorooj), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempKardeks Set fldKolMande=Convert(varchar,floor(SumMandeJoz / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,SumMandeJoz), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempKardeks Set fldTedadVoroodKartonShow='' where fldTedadeJozVorood=0
update #TempKardeks Set fldTedadKhoroojKartonShow='' where fldTedadeJozKhorooj=0



--update #TempKardeks Set fldTedadKhoroojKartonShow=Convert(varchar,floor(fldTedadeJozKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldTedadeJozKhorooj, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--	where fldTedadDarKarton>0

--جمع ستونها
--SELECT
--  AccountNumber,
--  flddate,
--  bill,
--  SUM(bill) OVER (PARTITION BY AccountNumber ORDER BY flddate) AS RunningTotal
--FROM
--  dbo.Table1 


----فیلتر تا قبل از تاریخ 
--Insert into #TempKardeksShow
--	(fldTedadeJozVorood,fldTedadeJozKhorooj,fldTedadDarKarton, NameGroup, CodeGroup, CodeKala, NameKala, fldNameVahed, fldNameVahed2)
--SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, 
--                         fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0
--FROM            #TempKardeks
--GROUP BY CodeKala, NameGroup, CodeGroup, NameKala, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol




	--Select CodeKala,NameKala,CodeGroup,NameGroup,fldShomareFactor,fldShomareSanad,fldDate,fldSharh,fldCodeAnbar,fldNameAnbar,fldFeeJoz,fldFeeYekKarton,fldMablaghKol,fldTedadeJozVorood,fldTedadeJozKhorooj,fldJozMande,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldKolMande,fldtype,fldNameVahed,fldNameVahed2
	--	from #TempKardeks
	--update 

	--Select fldTedadeJozVorood,fldTedadeJozKhorooj,fldDate,fldShomareSanad,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldTedadDarKartonShow,SUM(fldTedadeJozVorood-fldTedadeJozKhorooj) OVER (PARTITION BY ConditionSum ORDER BY fldDate,fldShomareSanad) AS RunningTotal from #TempKardeks
	update #TempKardeks set fldTypeShow='خرید' where fldType='kharid'
	update #TempKardeks set fldTypeShow='ابتدای دوره' where fldType='mojodi_ebteda_doreh'	
	update #TempKardeks set fldTypeShow='انتقال بین انبار' where fldType='enteghal'
	update #TempKardeks set fldTypeShow='فروش' where fldType='foroosh'
	update #TempKardeks set fldTypeShow='برگشت از فروش' where fldType='bargashtazforoosh'
	update #TempKardeks set fldTypeShow='برگشت از خرید' where fldType='bargashtazkharid'
	update #TempKardeks set fldTypeShow='تبدیل به محصول نهایی' where fldType='avalie'
	update #TempKardeks set fldTypeShow='محصول تولید شده در فرایند تولید' where fldType='mahsool'
	update #TempKardeks set fldTypeShow='مغایرت',fldCodeTafsili=0,fldSharh='مغایرت' where fldType='Moghayrat'

	
	update #TempKardeks set fldShomareFactor=fldShomareEnteghal where fldType='enteghal'

	update #TempKardeks set fldSharh= tblTafzili.fldSharheTafzili + ' ' + fldSharh from tblTafzili 
		Where #TempKardeks.fldCodeTafsili=tblTafzili.fldCodeTafzili

	
	update #TempKardeks set flddateshow =substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2)
	Select  ROW_NUMBER() OVER(ORDER BY flddate,fldshomaresanad ) AS Row,id,fldSharh,fldtypeShow,fldShomareFactor,flddateshow,fldTedadeJozVoroodT As fldTedadeJozVorood,fldTedadeJozKhoroojT as fldTedadeJozKhorooj,SumMandeJozT as SumMandeJoz,fldNameVahed,fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekKarton,fldMablaghKol,fldTedadVoroodKartonShow,fldTedadKhoroojKartonShow,fldTedadDarKarton,fldNameVahed2,fldKolMande,fldShomareSanad,fldNameAnbar,fldDate,fldtype,fldRadif from #TempKardeks order by Convert(varchar,IdOrder)
	
--FROM
--  dbo.Table1 

END
GO

-- ===============================================
-- SP: [dbo].[KardeksNew]
-- ===============================================
IF OBJECT_ID(N'dbo.KardeksNew', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KardeksNew] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KardeksNew]

--@mm nvarchar(10),
--@nn nvarchar(10)

as
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END

begin
 

create table #TempMojoodieAnbar5(

fldGroupName nvarchar(50)  COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100)  COLLATE Persian_100_CI_AS,
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)  COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100)  COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100)  COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20)  COLLATE Persian_100_CI_AS
)



--insert into #TempMojoodieAnbar5 (
--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 #TempMojoodieAnbar5
                         (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 #TempMojoodieAnbar5
                         (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       #TempMojoodieAnbar5
SET                fldCodeGroup = tblKala.fldCodeGroup, fldNameKala = tblKala.fldNameKala, fldNogheSefaresh = tblKala.fldNogheSefaresh,fldTedadDarKarton=tblKala.fldTedadJoz
FROM            tblKala INNER JOIN
                         #TempMojoodieAnbar5 ON tblKala.fldCodeKala = #TempMojoodieAnbar5.fldCodeKala


UPDATE       #TempMojoodieAnbar5
SET                #TempMojoodieAnbar5.fldGroupName = tblGroupKala.fldGroupName
FROM            tblGroupKala INNER JOIN
                         #TempMojoodieAnbar5 ON #TempMojoodieAnbar5.fldCodeGroup = tblGroupKala.fldGroupId


UPDATE       #TempMojoodieAnbar5
SET                fldNameAnbar = tblAnbar.fldNameAnbar
FROM            tblAnbar INNER JOIN
                         #TempMojoodieAnbar5 ON tblAnbar.fldCode = #TempMojoodieAnbar5.fldCodeAnbar


update #TempMojoodieAnbar5 set #TempMojoodieAnbar5.fldNameVahed=tbl2.fldNameVahed,#TempMojoodieAnbar5.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=#TempMojoodieAnbar5.fldCodeKala

delete  from #TempMojoodieAnbar5  where fldCodeKala<>11001
Select * from #TempMojoodieAnbar5 
end
GO

-- ===============================================
-- SP: [dbo].[KardeksNew2]
-- ===============================================
IF OBJECT_ID(N'dbo.KardeksNew2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KardeksNew2] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KardeksNew2]

--@mm nvarchar(10),
--@nn nvarchar(10)

as
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END

begin
 

create table #TempMojoodieAnbar5(

fldGroupName nvarchar(50)  COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100)  COLLATE Persian_100_CI_AS,
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)  COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100)  COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100)  COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20)  COLLATE Persian_100_CI_AS
)



--insert into #TempMojoodieAnbar5 (
--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 #TempMojoodieAnbar5
                         (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 #TempMojoodieAnbar5
                         (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       #TempMojoodieAnbar5
SET                fldCodeGroup = tblKala.fldCodeGroup, fldNameKala = tblKala.fldNameKala, fldNogheSefaresh = tblKala.fldNogheSefaresh,fldTedadDarKarton=tblKala.fldTedadJoz
FROM            tblKala INNER JOIN
                         #TempMojoodieAnbar5 ON tblKala.fldCodeKala = #TempMojoodieAnbar5.fldCodeKala


UPDATE       #TempMojoodieAnbar5
SET                #TempMojoodieAnbar5.fldGroupName = tblGroupKala.fldGroupName
FROM            tblGroupKala INNER JOIN
                         #TempMojoodieAnbar5 ON #TempMojoodieAnbar5.fldCodeGroup = tblGroupKala.fldGroupId


UPDATE       #TempMojoodieAnbar5
SET                fldNameAnbar = tblAnbar.fldNameAnbar
FROM            tblAnbar INNER JOIN
                         #TempMojoodieAnbar5 ON tblAnbar.fldCode = #TempMojoodieAnbar5.fldCodeAnbar


update #TempMojoodieAnbar5 set #TempMojoodieAnbar5.fldNameVahed=tbl2.fldNameVahed,#TempMojoodieAnbar5.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=#TempMojoodieAnbar5.fldCodeKala

delete  from #TempMojoodieAnbar5  where fldCodeKala<>11001
Select * from #TempMojoodieAnbar5 
end
GO

-- ===============================================
-- SP: [dbo].[Kardex]
-- ===============================================
IF OBJECT_ID(N'dbo.Kardex', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Kardex] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[Kardex] 
@CodeKala bigint,
@DateFrom bigint,
@DateUntil bigint

AS
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
BEGIN

create table #TempMojoodieAnbar6(

fldGroupName nvarchar(50)  COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100)  COLLATE Persian_100_CI_AS,
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)  COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100)  COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100)  COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20)  COLLATE Persian_100_CI_AS
)



--insert into #TempMojoodieAnbar6 (
--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 #TempMojoodieAnbar6
                         (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 
	where fldCodeKala=@CodeKala And fldDate between @Datefrom And @DateUntil




INSERT INTO #TempMojoodieAnbar6
                         (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
	where fldCodeKala=@CodeKala And fldDate between @Datefrom And @DateUntil


INSERT INTO #TempMojoodieAnbar6
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz,0 , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeBargashtAzForoosh
	where fldCodeKala=@CodeKala And fldDate between @Datefrom And @DateUntil


INSERT INTO #TempMojoodieAnbar6
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0, fldTedadJoz , - 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            tblRizeBargashtAzKharid
	where fldCodeKala=@CodeKala And fldDate between @Datefrom And @DateUntil


UPDATE       #TempMojoodieAnbar6
SET                fldCodeGroup = tblKala.fldCodeGroup, fldNameKala = tblKala.fldNameKala, fldNogheSefaresh = tblKala.fldNogheSefaresh,fldTedadDarKarton=tblKala.fldTedadJoz
FROM            tblKala INNER JOIN
                         #TempMojoodieAnbar6 ON tblKala.fldCodeKala = #TempMojoodieAnbar6.fldCodeKala


UPDATE       #TempMojoodieAnbar6
SET                #TempMojoodieAnbar6.fldGroupName = tblGroupKala.fldGroupName
FROM            tblGroupKala INNER JOIN
                         #TempMojoodieAnbar6 ON #TempMojoodieAnbar6.fldCodeGroup = tblGroupKala.fldGroupId


UPDATE       #TempMojoodieAnbar6
SET                fldNameAnbar = tblAnbar.fldNameAnbar
FROM            tblAnbar INNER JOIN
                         #TempMojoodieAnbar6 ON tblAnbar.fldCode = #TempMojoodieAnbar6.fldCodeAnbar


update #TempMojoodieAnbar6 set #TempMojoodieAnbar6.fldNameVahed=tbl2.fldNameVahed,#TempMojoodieAnbar6.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=#TempMojoodieAnbar6.fldCodeKala

--delete  from #TempMojoodieAnbar6  where fldCodeKala<>1001
Select * from #TempMojoodieAnbar6 

END
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareBazPas]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareBazPas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareBazPas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KoochakBozorgShomareBazPas]
@Type nvarchar(50),
@ShomareBazPasJari bigint,
@NewShomareBazPas bigint output

as

begin
	if @Type='koochak'
		begin
		 set @NewShomareBazPas=(	SELECT        ISNULL( max(fldShomareBazPas),@ShomareBazPasJari) AS Expr1
				FROM            tblCheckePardakhti
				WHERE        (fldShomareBazPas < @ShomareBazPasJari))
		 --insert into tbltest7	(fld2)
			--values(@ShomarePardakhteJari)
		end

	if @Type='bozorg'
		begin
		set @NewShomareBazPas=(	SELECT        isnull( min(fldShomareBazPas),@ShomareBazPasJari) AS Expr1
				FROM            tblCheckePardakhti
				WHERE        (fldShomareBazPas > @ShomareBazPasJari))
		end
end
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareDaryaft]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareDaryaft', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareDaryaft] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareEnteghal]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareEnteghal', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareEnteghal] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareFactorAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareFactorAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareFactorAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KoochakBozorgShomareFactorAmani]
@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(fldShomareAmani),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizeForoosh
				WHERE        (fldShomareAmani < @ShomareFactorForooshJari and fldType=@TypeForm))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareFactorForoosh=(	SELECT        isnull( min(fldShomareAmani),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizeForoosh
				WHERE        (fldShomareAmani > @ShomareFactorForooshJari  and fldType=@TypeForm))
		end
end
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareFactorBargashtAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareFactorBargashtAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareFactorBargashtAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KoochakBozorgShomareFactorBargashtAmani]
@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(fldShomareBargashtAmani),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizeBargashtAzForoosh
				WHERE        (fldShomareBargashtAmani < @ShomareFactorForooshJari and fldType=@TypeForm))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareFactorForoosh=(	SELECT        isnull( min(fldShomareBargashtAmani),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizeBargashtAzForoosh
				WHERE        (fldShomareBargashtAmani > @ShomareFactorForooshJari  and fldType=@TypeForm))
		end
end
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareFactorBargashtAzForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareFactorBargashtAzForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareFactorBargashtAzForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareFactorBargashtAzKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareFactorBargashtAzKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareFactorBargashtAzKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareFactorForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareFactorForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareFactorForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KoochakBozorgShomareFactorForoosh]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareFactorForooshJari bigint,
@UserCode bigint,
@NewShomareFactorForoosh bigint output

as

begin
   		declare @Access nvarchar(5) 
		set @Access=(select fldMeghdar from tblTanzimateKol Where fldtype='ACCESSGROUPASHKHAS')
       SET NOCOUNT ON;
  
	if @Type='koochak'
		begin
		if @Access='True'
			 set @NewShomareFactorForoosh=(	SELECT        ISNULL( max(fldShomareFactor),0) AS Expr1
					FROM            tblRizeForoosh
					WHERE        (fldShomareFactor < @ShomareFactorForooshJari and fldType=@TypeForm) and fldCodeTafsili in ( Select fldCodeTafzili from tbltafzili where substring(convert(varchar,fldcodegroup),1,3) in 
				(SELECT  distinct  substring(convert(varchar,fldGroupCode),1,3)
				FROM         tblGroupAshkhasAccess
				WHERE     (fldUserCode = @UserCode))  ))
		else
			set @NewShomareFactorForoosh=(	SELECT        ISNULL( max(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
					FROM            tblRizeForoosh
					WHERE        (fldShomareFactor < @ShomareFactorForooshJari and fldType=@TypeForm))
		
		end

	if @Type='bozorg'
		begin
		if @Access='True'
			set @NewShomareFactorForoosh=(	SELECT        ISNULL( min(fldShomareFactor),0) AS Expr1
						FROM            tblRizeForoosh
						WHERE        (fldShomareFactor > @ShomareFactorForooshJari and fldType=@TypeForm) and fldCodeTafsili in ( Select fldCodeTafzili from tbltafzili where substring(convert(varchar,fldcodegroup),1,3) in 
					(SELECT  distinct  substring(convert(varchar,fldGroupCode),1,3)
					FROM         tblGroupAshkhasAccess
					WHERE     (fldUserCode = @UserCode))  ))
		else
			set @NewShomareFactorForoosh=(	SELECT        isnull( min(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizeForoosh
				WHERE        (fldShomareFactor > @ShomareFactorForooshJari  and fldType=@TypeForm))
		end
end
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareFactorKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareFactorKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareFactorKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareFactorPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareFactorPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareFactorPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KoochakBozorgShomareFactorPishForoosh]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareFactorForooshJari bigint,
@UserCode bigint,
@NewShomareFactorForoosh bigint output

as

begin
   
       SET NOCOUNT ON;


	  -- Select fldCodeTafzili from tbltafzili where substring(convert(varchar,fldcodegroup),1,3) in 
			--(SELECT  distinct  substring(convert(varchar,fldGroupCode),1,3)
			--FROM         tblGroupAshkhasAccess
			--WHERE     (fldUserCode = @UserCode))

		declare @Access nvarchar(5) 
		set @Access=(select fldMeghdar from tblTanzimateKol Where fldtype='ACCESSGROUPASHKHAS')

	if @Type='koochak'
		begin
		

		if @Access='True'
			 set @NewShomareFactorForoosh=(	SELECT        ISNULL( max(fldShomareFactor),0) AS Expr1
					FROM            tblRizePishForoosh
					WHERE        (fldShomareFactor < @ShomareFactorForooshJari and fldType=@TypeForm) and fldCodeTafsili in ( Select fldCodeTafzili from tbltafzili where substring(convert(varchar,fldcodegroup),1,3) in 
				(SELECT  distinct  substring(convert(varchar,fldGroupCode),1,3)
				FROM         tblGroupAshkhasAccess
				WHERE     (fldUserCode = @UserCode))  ))
		else
			set @NewShomareFactorForoosh=(	SELECT        ISNULL( max(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
				FROM            tblRizePishForoosh
				WHERE        (fldShomareFactor < @ShomareFactorForooshJari and fldType=@TypeForm))
		
		end

	if @Type='bozorg'
		begin
		if @Access='True'
			set @NewShomareFactorForoosh=(	SELECT        ISNULL( min(fldShomareFactor),0) AS Expr1
					FROM            tblRizePishForoosh
					WHERE        (fldShomareFactor > @ShomareFactorForooshJari and fldType=@TypeForm) and fldCodeTafsili in ( Select fldCodeTafzili from tbltafzili where substring(convert(varchar,fldcodegroup),1,3) in 
				(SELECT  distinct  substring(convert(varchar,fldGroupCode),1,3)
				FROM         tblGroupAshkhasAccess
				WHERE     (fldUserCode = @UserCode))  ))
		else
			set @NewShomareFactorForoosh=(	SELECT        isnull( min(fldShomareFactor),@ShomareFactorForooshJari) AS Expr1
			FROM            tblRizePishForoosh
			WHERE        (fldShomareFactor > @ShomareFactorForooshJari  and fldType=@TypeForm))
		end
end
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareFactorPishPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareFactorPishPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareFactorPishPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareHavale]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareHavale', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareHavale] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KoochakBozorgShomareHavale]
@Type nvarchar(50),
@TypeForm nvarchar(50),
@ShomareHavaleJari bigint,
@typeReg  nvarchar(10) ,
@NewShomareHavale bigint output

as

begin
   
       SET NOCOUNT ON;
  
	if @Type='koochak'
		begin
		 --set @NewShomareHavale=(	SELECT        ISNULL( max(fldShomareHavale),@ShomareHavaleeJari) AS Expr1
			--	FROM            tblHavale
			--	WHERE        (fldShomareHavale < @ShomareHavaleeJari and fldType=@TypeForm))
			set @NewShomareHavale=(	SELECT        ISNULL( max(fldShomareHavale),@ShomareHavaleJari) AS Expr1
				FROM            tblHavaleGoroohi
				WHERE        (fldShomareHavale < @ShomareHavaleJari ) and fldType=@typeReg)
		
		end

	if @Type='bozorg'
		begin
		--set @NewShomareHavale=(	SELECT        isnull( min(fldShomareHavale),@ShomareHavaleeJari) AS Expr1
		--		FROM            tblHavale
		--		WHERE        (fldShomareHavale > @ShomareHavaleeJari  and fldType=@TypeForm))
		set @NewShomareHavale=(	SELECT        isnull( min(fldShomareHavale),@ShomareHavaleJari) AS Expr1
				FROM            tblHavaleGoroohi
				WHERE        (fldShomareHavale > @ShomareHavaleJari )  and fldType=@typeReg)
		end
end
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomarePardakht]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomarePardakht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomarePardakht] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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' and fldType<>'pardakhtpersonel' and fldType<>'pardakhtsayer') 
		 --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' and fldType<>'pardakhtpersonel' and fldType<>'pardakhtsayer') 
		end
end
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomarePardakhtEnteghaleVajh]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomarePardakhtEnteghaleVajh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomarePardakhtEnteghaleVajh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomarePardakhtHazine]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomarePardakhtHazine', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomarePardakhtHazine] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomarePardakhtPersonel]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomarePardakhtPersonel', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomarePardakhtPersonel] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KoochakBozorgShomarePardakhtPersonel]
@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='pardakhtpersonel') 
		 --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='pardakhtpersonel') 
		end
end
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomarePardakhtSayer]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomarePardakhtSayer', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomarePardakhtSayer] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KoochakBozorgShomarePardakhtSayer]
@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='pardakhtsayer') 
		 --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='pardakhtsayer') 
		end
end
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomarePasCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomarePasCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomarePasCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareSanad_MojodiEbteda_doreh]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareSanad_MojodiEbteda_doreh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareSanad_MojodiEbteda_doreh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareTolid]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareTolid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareTolid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KoochakBozorgShomareTolid]
@Type nvarchar(50),
@ShomareTolidJari bigint,
@NewShomareTolid bigint output

as

begin
   
       SET NOCOUNT ON;
  
	if @Type='koochak'
		begin
		 set @NewShomareTolid=(	SELECT        ISNULL( max(fldShomareTolid),@ShomareTolidJari) AS Expr1
				FROM            tblRizeTolid
				WHERE        (fldShomareTolid < @ShomareTolidJari ))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareTolid=(	SELECT        isnull( min(fldShomareTolid),@ShomareTolidJari) AS Expr1
				FROM            tblRizeTolid
				WHERE        (fldShomareTolid > @ShomareTolidJari  ))
		end
end
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareVam]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareVam', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareVam] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[KoochakBozorgShomareVam]
@Type nvarchar(50),
@ShomareVamJari bigint,
@NewShomareVam bigint output

as

begin
   
       SET NOCOUNT ON;
  
	if @Type='koochak'
		begin
		 set @NewShomareVam=(	SELECT        ISNULL( max(fldShomareVam),@ShomareVamJari) AS Expr1
				FROM            tblVamInfo
				WHERE        (fldShomareVam < @ShomareVamJari ))
		
		end

	if @Type='bozorg'
		begin
		set @NewShomareVam=(	SELECT        isnull( min(fldShomareVam),@ShomareVamJari) AS Expr1
				FROM            tblVamInfo
				WHERE        (fldShomareVam > @ShomareVamJari  ))
		end
end
GO

-- ===============================================
-- SP: [dbo].[KoochakBozorgShomareVosoolCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.KoochakBozorgShomareVosoolCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[KoochakBozorgShomareVosoolCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[LastFeeKharidVaTolid]
-- ===============================================
IF OBJECT_ID(N'dbo.LastFeeKharidVaTolid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LastFeeKharidVaTolid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[LastFeeKharidVaTolid]
@CodeKala bigint


as

begin
		SELECT fldMablaghKhales, fldArzeshAfzode,fldTedadJoz,fldDate
			FROM tblRizeKharid where fldCodeKala= @CodeKala   and fldtype<>'enteghal'
			UNION ALL  
		SELECT fldMablaghKhales, 0,  fldTedadJozNahaei,fldDate
			FROM tblRizetolid where fldType='mahsool' and fldCodeKala= @CodeKala 
		order by fldDate desc


end
GO

-- ===============================================
-- SP: [dbo].[ListeAghsateTasfieNashode]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeAghsateTasfieNashode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeAghsateTasfieNashode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeAghsateTasfieNashode] 
	@CodeTafzili nvarchar(10),
	@ShomareDaryaft bigint
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie2(
	[fldShomareVam] [bigint]  null,
	[fldShomareGhest] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheMande][bigint],	
	[fldMablagheDaryaftiJari] [bigint],
	[fldDateSarResid][bigint],
	[ShomareDaryaft][bigint]

	)

		

	insert into #tmpDaryaftTasfie2
		(fldShomareVam,fldShomareGhest,SumDaryafti,fldCodeTafzili,fldMablagheMande,fldDateSarResid)
		Select  tblDaftarcheAghsat.fldShomareVam,fldRadif,0,fldCodeTafzili, tblDaftarcheAghsat.fldMablaghGhest,fldDateSarResid
			from tblDaftarcheAghsat
			inner join tblVamInfo
			on tblDaftarcheAghsat.fldShomareVam =tblVamInfo.fldShomareVam
			where fldCodeTafzili = @CodeTafzili
	--insert into #tmpDaryaftTasfie2
	--	(fldShomarePeigiri,fldShomareVam,fldShomareGhest,SumDaryafti,fldCodeTafzili,fldMablagheMande,fldDateSarResid)
	--	Select Convert(varchar,tblDaftarcheAghsat.fldShomareVam) +  Convert(varchar,tblDaftarcheAghsat.fldRadif), tblDaftarcheAghsat.fldShomareVam,fldRadif,0,fldCodeTafzili, tblDaftarcheAghsat.fldMablaghGhest,fldDateSarResid
	--		from tblDaftarcheAghsat
	--		inner join tblVamInfo
	--		on tblDaftarcheAghsat.fldShomareVam =tblVamInfo.fldShomareVam
	--		where fldCodeTafzili = @CodeTafzili
	--select * from #tmpDaryaftTasfie2
	update #tmpDaryaftTasfie2
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareVam,fldShomareGhest, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfieVam group by fldShomareVam,fldShomareGhest ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie2.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie2.fldShomareVam=tbl1.fldShomareVam and  #tmpDaryaftTasfie2.fldShomareGhest=tbl1.fldShomareGhest


		update #tmpDaryaftTasfie2 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
			(Select fldShomareVam,fldShomareGhest, fldMablagh from tblRizeTasfieVam Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
			where tbl2.fldShomareVam=#tmpDaryaftTasfie2.fldShomareVam and tbl2.fldShomareGhest=#tmpDaryaftTasfie2.fldShomareGhest
	--update #tmpDaryaftTasfie2 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select (Convert(varchar,fldShomareVam) +  Convert(varchar,fldShomareGhest)) As fldShomarePeigiri, fldMablagh from tblRizeTasfieVam Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareVam=#tmpDaryaftTasfie2.fldShomareVam

	update #tmpDaryaftTasfie2 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null

	Select fldShomareVam,fldShomareGhest,SumDaryafti,fldMablagheMande,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,fldShomareVam

END
GO

-- ===============================================
-- SP: [dbo].[ListeAshkhasBaMande]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeAshkhasBaMande', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeAshkhasBaMande] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeAshkhasBaMande]
	-- Add the parameters for the stored procedure here	
	@Filter nvarchar(15) output,
	@BetafkikeVizitor int,
	@Mobile int,
	@Date int,
	@ListGroupAshkhas varchar(5000)=null
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)  COLLATE Persian_100_CI_AS,
		fldSharheTafzili nvarchar(200) COLLATE Persian_100_CI_AS,
		fldBedehkar bigint,
		fldBestankar Bigint,
		fldMande bigint,
		fldAdress nvarchar(200) COLLATE Persian_100_CI_AS,
		fldTell nvarchar(50) COLLATE Persian_100_CI_AS,
		fldCodeGroup nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameGroup nvarchar(50) COLLATE Persian_100_CI_AS,
		fldVisitor bigint,
		fldNameVisitor nvarchar(200) COLLATE Persian_100_CI_AS
	)
	
    declare @CodeKolDaryaftani nvarchar(100),@CodeKolPardakhtani nvarchar(100)

	execute CodeKolHesab 'kolhesabhayedaryaftani',@CodeKolDaryaftani output
	execute CodeKolHesab 'kolhesabhayepardakhtani',@CodeKolPardakhtani output
	--declare @BetafkikeVizitor int,@Filter nvarchar(15)
	--set @BetafkikeVizitor=1
	--set @Filter ='bedehkaran'
	--delete #TempListeAshkhas3
	if @BetafkikeVizitor=1
		Insert into #TempListeAshkhas3 (fldCodetafzili,fldBedehkar,fldBestankar,fldMande,fldVisitor)	
			SELECT        fldCodeTafzili, SUM(fldBedehkar) AS sumBed, SUM(fldBestankar) AS SumBes, SUM(fldBedehkar - fldBestankar) AS Mande,fldVasete
				FROM            tblSodooreSanad
				WHERE   ( Convert(bigint,fldDate)<=@Date) and (     (fldCodeKol = @CodeKolDaryaftani) OR
										 (fldCodeKol= @CodeKolPardakhtani) and fldCodeNoeTafzili='1' )
				GROUP BY fldCodeTafzili,fldVasete
	else		
		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   ( Convert(bigint,fldDate)<=@Date) and (     (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)

	if @BetafkikeVizitor=1
		update #TempListeAshkhas3  set fldSharheTafzili=tblTafzili.fldSharheTafzili,  fldAdress=tblTafzili.fldAddress  from tblTafzili
			where #TempListeAshkhas3.fldCodetafzili=tblTafzili.fldCodeTafzili
	else
		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

	--update #TempListeAshkhas3  set  fldTell=(Select top(1)  fldShomare from tblDaftarcheTell Where fldCodetafzili=@EmpCodeTafzili)
	--						where fldCodetafzili=@EmpCodeTafzili

	--update #TempListeAshkhas3  set  fldTell=
	--(select fldShomare from
	--	(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
	--	FROM            [tblDaftarcheTell]) DB_Address
	--	where RowNo=1) as tbl2
	--	where #TempListeAshkhas3.fldCodetafzili=tbl1.fldCodetafzili


		update #TempListeAshkhas3 set fldTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempListeAshkhas3.fldCodetafzili=tbl5.fldCodeTafzili


	--if @mobile=1 
	--	begin
	--		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
	--	end


	--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
	update #TempListeAshkhas3 set fldNameVisitor='بدون واسطه'  where fldNameVisitor is NUll

	if @Filter='bedehkaran' 
		delete #TempListeAshkhas3 Where fldMande<=0
	
	if @Filter='bestankaran'
		begin
			delete #TempListeAshkhas3 Where fldMande>=0
			update #TempListeAshkhas3 set fldMande=-1*fldMande
		end
	
	--برای حسابهایی که تفصیلی ندارن،برای سندهای دستی
	delete from #TempListeAshkhas3 Where fldCodetafzili =''

	if @ListGroupAshkhas<>''
		begin
		declare @StrDeleteGroupAshkhas varchar(5000)
		set  @StrDeleteGroupAshkhas='delete from #TempListeAshkhas3 
		    where '+ @ListGroupAshkhas + ''
			execute(@StrDeleteGroupAshkhas)
		end
	
	select fldNameGroup,fldCodetafzili,fldSharheTafzili, fldBedehkar,fldBestankar,fldMande,fldVisitor,fldTell,fldAdress,fldCodeGroup,fldNameVisitor from #TempListeAshkhas3


END
GO

-- ===============================================
-- SP: [dbo].[ListeAshkhasBaMande_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeAshkhasBaMande_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeAshkhasBaMande_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeAshkhasBaMande_WithUserCode]
	-- Add the parameters for the stored procedure here	
	@Filter nvarchar(19) ,
	@BetafkikeVizitor int,
	@Mobile int,
	@Date int,
	@ListGroupAshkhas varchar(5000)=null,
	@userCode bigint
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)  COLLATE Persian_100_CI_AS,
		fldSharheTafzili nvarchar(200) COLLATE Persian_100_CI_AS,
		fldBedehkar bigint,
		fldBestankar Bigint,
		fldMande bigint,
		fldAdress nvarchar(200) COLLATE Persian_100_CI_AS,
		fldTell nvarchar(50) COLLATE Persian_100_CI_AS,
		fldCodeGroup nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameGroup nvarchar(50) COLLATE Persian_100_CI_AS,
		fldVisitor bigint,
		fldNameVisitor nvarchar(200) COLLATE Persian_100_CI_AS,
		fldLastDateForoosh  nvarchar(12),
		fldLastDateDaryaft  nvarchar(12),
		fldLastDatekharid  nvarchar(12),
		fldLastDatePardakht  nvarchar(12)
	)
	
    declare @CodeKolDaryaftani nvarchar(100),@CodeKolPardakhtani nvarchar(100)

	execute CodeKolHesab 'kolhesabhayedaryaftani',@CodeKolDaryaftani output
	execute CodeKolHesab 'kolhesabhayepardakhtani',@CodeKolPardakhtani output
	--declare @BetafkikeVizitor int,@Filter nvarchar(15)
	--set @BetafkikeVizitor=1
	--set @Filter ='bedehkaran'
	--delete #TempListeAshkhas3

	--update tblSodooreSanad set fldCodeNoeTafzili = tblTafzili.fldCodeNoe from tblTafzili where tblSodooreSanad.fldCodeTafzili=tblTafzili.fldcodenoe

	if @BetafkikeVizitor=1
		Insert into #TempListeAshkhas3 (fldCodetafzili,fldBedehkar,fldBestankar,fldMande,fldVisitor)	
			SELECT        fldCodeTafzili, SUM(fldBedehkar) AS sumBed, SUM(fldBestankar) AS SumBes, SUM(fldBedehkar - fldBestankar) AS Mande,fldVasete
				FROM            tblSodooreSanad
				WHERE not( fldType='pasecheck') and  ( Convert(bigint,fldDate)<=@Date) and (     (fldCodeKol = @CodeKolDaryaftani) OR
										 (fldCodeKol= @CodeKolPardakhtani)  )
				GROUP BY fldCodeTafzili,fldVasete
	else if @BetafkikeVizitor=2
		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  not( fldType='pasecheck') and ( Convert(bigint,fldDate)<=@Date) and (     (fldCodeKol = @CodeKolDaryaftani) OR
											 (fldCodeKol= @CodeKolPardakhtani)  )
					GROUP BY fldCodeTafzili
	else		
		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  not( fldType='pasecheck') and ( Convert(bigint,fldDate)<=@Date) and (     (fldCodeKol = @CodeKolDaryaftani) OR
										 (fldCodeKol= @CodeKolPardakhtani)  )
				GROUP BY fldCodeTafzili


	Insert into #TempListeAshkhas3 (fldCodetafzili,fldBedehkar,fldBestankar,fldMande)
		Select fldCodeTafzili, 0, 0, 0 from tblTafzili
			Where  fldCodeTafzili Not In (Select fldCodeTafzili from #TempListeAshkhas3)

	if (@BetafkikeVizitor=1 or @BetafkikeVizitor=2)
		update #TempListeAshkhas3  set fldSharheTafzili=tblTafzili.fldSharheTafzili,  fldAdress=tblTafzili.fldAddress  from tblTafzili
			where #TempListeAshkhas3.fldCodetafzili=tblTafzili.fldCodeTafzili
	else
		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

	--update #TempListeAshkhas3  set  fldTell=(Select top(1)  fldShomare from tblDaftarcheTell Where fldCodetafzili=@EmpCodeTafzili)
	--						where fldCodetafzili=@EmpCodeTafzili

	--update #TempListeAshkhas3  set  fldTell=
	--(select fldShomare from
	--	(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
	--	FROM            [tblDaftarcheTell]) DB_Address
	--	where RowNo=1) as tbl2
	--	where #TempListeAshkhas3.fldCodetafzili=tbl1.fldCodetafzili


		update #TempListeAshkhas3 set fldTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempListeAshkhas3.fldCodetafzili=tbl5.fldCodeTafzili


	--if @mobile=1 
	--	begin
	--		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
	--	end


	--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
	update #TempListeAshkhas3 set fldNameVisitor='بدون واسطه'  where fldNameVisitor is NUll

	if @Filter='bedehkaran' 
		delete #TempListeAshkhas3 Where fldMande<=0
	
	if @Filter='bestankaran'
		begin
			delete #TempListeAshkhas3 Where fldMande>=0
			update #TempListeAshkhas3 set fldMande=-1*fldMande
		end
	
	--برای حسابهایی که تفصیلی ندارن،برای سندهای دستی
	delete from #TempListeAshkhas3 Where fldCodetafzili =''

	if @ListGroupAshkhas<>''
		begin
		declare @StrDeleteGroupAshkhas varchar(5000)
		set  @StrDeleteGroupAshkhas='delete from #TempListeAshkhas3 
		    where '+ @ListGroupAshkhas + ''
			execute(@StrDeleteGroupAshkhas)
		end

	--select flddate,fldcodetafsili from tblRizeForoosh order by flddate

	update #TempListeAshkhas3 set fldLastDateForoosh=tbl5.fldDate from
		(select fldDate,fldCodeTafsili from
			(SELECT         fldCodeTafsili,row_number() over (partition by fldCodeTafsili order by fldCodeTafsili,fldDate desc) RowNo,fldDate
			FROM            [tblRizeForoosh]) DB_Address
			where RowNo=1) as tbl5 
			where #TempListeAshkhas3.fldCodetafzili=tbl5.fldCodeTafsili
			

	update #TempListeAshkhas3 set fldLastDateDaryaft=tbl5.fldDate from
		(select fldDate,fldCodeTafzili from
			(SELECT         fldCodeTafzili,row_number() over (partition by fldCodeTafzili order by fldCodeTafzili,fldDate desc) RowNo,fldDate
			FROM            [tblSodooreSanad] where not( fldType='pasecheck') and fldSanad in (select fldShomareSanad from tbldaryaft ) and isnumeric(fldCodeTafzili)=1) DB_Address
			where RowNo=1) as tbl5 
			where #TempListeAshkhas3.fldCodetafzili=tbl5.fldCodeTafzili

	update #TempListeAshkhas3 set fldLastDateDaryaft='0' where fldLastDateDaryaft is null
	update #TempListeAshkhas3 set fldLastDateForoosh='0' where fldLastDateForoosh is null	

	update #TempListeAshkhas3 set fldLastDateDaryaft=substring(convert(nvarchar(10),fldLastDateDaryaft),0,5) +'/' +substring(convert(nvarchar(10),fldLastDateDaryaft),5,2) + '/' + substring(convert(nvarchar(10),fldLastDateDaryaft),7,2) where fldLastDateDaryaft <>'0'
	update #TempListeAshkhas3 set fldLastDateForoosh=substring(convert(nvarchar(10),fldLastDateForoosh),0,5) +'/' +substring(convert(nvarchar(10),fldLastDateForoosh),5,2) + '/' + substring(convert(nvarchar(10),fldLastDateForoosh),7,2) where fldLastDateForoosh <>'0'






		update #TempListeAshkhas3 set fldLastDatekharid=tbl5.fldDate from
		(select fldDate,fldCodeTafsili from
			(SELECT         fldCodeTafsili,row_number() over (partition by fldCodeTafsili order by fldCodeTafsili,fldDate desc) RowNo,fldDate
			FROM            [tblRizeKharid]) DB_Address
			where RowNo=1) as tbl5 
			where #TempListeAshkhas3.fldCodetafzili=tbl5.fldCodeTafsili
			

	update #TempListeAshkhas3 set fldLastDatePardakht=tbl5.fldDate from
		(select fldDate,fldCodeTafzili from
			(SELECT         fldCodeTafzili,row_number() over (partition by fldCodeTafzili order by fldCodeTafzili,fldDate desc) RowNo,fldDate
			FROM            [tblSodooreSanad] where not( fldType='pasecheck') and fldSanad in (select fldShomareSanad from tblPardakht ) and isnumeric(fldCodeTafzili)=1) DB_Address
			where RowNo=1) as tbl5 
			where #TempListeAshkhas3.fldCodetafzili=tbl5.fldCodeTafzili

	update #TempListeAshkhas3 set fldLastDatePardakht='0' where fldLastDatePardakht is null
	update #TempListeAshkhas3 set fldLastDatekharid='0' where fldLastDatekharid is null	

	update #TempListeAshkhas3 set fldLastDatepardakht=substring(convert(nvarchar(10),fldLastDatepardakht),0,5) +'/' +substring(convert(nvarchar(10),fldLastDatepardakht),5,2) + '/' + substring(convert(nvarchar(10),fldLastDatepardakht),7,2) where fldLastDatepardakht <>'0'
	update #TempListeAshkhas3 set fldLastDatekharid=substring(convert(nvarchar(10),fldLastDatekharid),0,5) +'/' +substring(convert(nvarchar(10),fldLastDatekharid),5,2) + '/' + substring(convert(nvarchar(10),fldLastDatekharid),7,2) where fldLastDatekharid <>'0'
	
			--where #TempListeAshkhas3.fldCodetafzili=tbl5.fldCodeTafsili


			--select * from tblsodooresanad where fldSanad in (select fldShomareSanad from tbldaryaft ) and isnumeric(fldCodeTafzili)=1
			--select * from tblSodooreSanad where fldmoinkamel='61202'
	
-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################	

	select fldNameGroup,fldCodetafzili,fldSharheTafzili, fldBedehkar,fldBestankar,fldMande,fldVisitor,fldTell,fldAdress,fldCodeGroup,fldNameVisitor ,fldLastDateForoosh,fldLastDateDaryaft,fldLastDatekharid,fldLastDatePardakht
	from #TempListeAshkhas3
	where fldCodetafzili in (select code from @accessCodes)


END
GO

-- ===============================================
-- SP: [dbo].[ListeBedehkaran]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeBedehkaran', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeBedehkaran] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ListeCheckhayePasNashode]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeCheckhayePasNashode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeCheckhayePasNashode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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) and isnumeric(fldShomareBazPas)=0
			ORDER BY fldDateSarResid
END
GO

-- ===============================================
-- SP: [dbo].[ListeCheckhayePasShode]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeCheckhayePasShode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeCheckhayePasShode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ListeCodeKalaForooshBargashAzForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeCodeKalaForooshBargashAzForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeCodeKalaForooshBargashAzForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeCodeKalaForooshBargashAzForoosh] 
	-- Add the parameters for the stored procedure here
	@DateFrom bigint,
	@DateUntil bigint
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;

    -- Insert statements for procedure here
	Create table #TempTable(
	fldCodeKala bigint
	)

	Insert into #TempTable
		(fldCodeKala)
		Select fldCodeKala from tblRizeForoosh Where fldDate between @DateFrom and @DateUntil

	Insert into #TempTable
		(fldCodeKala)
		Select fldCodeKala from tblRizeBargashtAzForoosh Where fldDate between @DateFrom and @DateUntil

	Select distinct fldCodekala from #TempTable
END
GO

-- ===============================================
-- SP: [dbo].[ListeFactorhayeTasfieNashode]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeFactorhayeTasfieNashode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeFactorhayeTasfieNashode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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) COLLATE Persian_100_CI_AS,
	[fldMablagheMande][bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,
	[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

-- ===============================================
-- SP: [dbo].[ListeFactorhayeTasfieNashodeAlarm]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeFactorhayeTasfieNashodeAlarm', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeFactorhayeTasfieNashodeAlarm] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeFactorhayeTasfieNashodeAlarm] 

	@CodeTafzili nvarchar(10),		
	@DataType varchar(40),
	@DateSarResidAz bigint,
	@DateSarResidTa bigint,
	@SumMandeTasfieNashode bigint output
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie4(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheMande][bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,	
	[fldDateSarResid][bigint],
	[fldDateFactor][bigint],
	[SharheTafzili][nvarchar](200) COLLATE Persian_100_CI_AS,
	[codeTafzili][nvarchar](10) COLLATE Persian_100_CI_AS,
	[Tell][nvarchar](50) COLLATE Persian_100_CI_AS,
	[Adress][nvarchar](200) COLLATE Persian_100_CI_AS

	)


	
	insert into #tmpDaryaftTasfie4
			(fldShomareFactor,fldCodeTafzili,SharheTafzili,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
			Select distinct dbo.tblTasfie.fldShomareFactor,dbo.tblTafzili.fldCodeTafzili, dbo.tblTafzili.fldSharheTafzili, fldMablagheMandeFactor,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
				from  dbo.tblTasfie INNER JOIN
				dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor 
				INNER JOIN dbo.tblTafzili on dbo.tblTasfie.fldCodeTafzili=dbo.tblTafzili.fldCodeTafzili
		if @Codetafzili<>0 --يعني همه افراد
			delete #tmpDaryaftTasfie4 where fldCodeTafzili<>@CodeTafzili

	update #tmpDaryaftTasfie4
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor





	update   #tmpDaryaftTasfie4 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti

	--بروزرساني کد تفصيلي
	update #tmpDaryaftTasfie4 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl3.fldShomareFactorForoosh


	--بروزرساني تاريخ سررسيد bm
	update #tmpDaryaftTasfie4 set fldDateSarResid=tbl9.fldDateSarResid from
	(select fldDateSarResid,fldShomareFactor from tblTasfie) as tbl9
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl9.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateSarResid< @DateSarResidAz
		delete #tmpDaryaftTasfie4 Where fldDateSarResid> @DateSarResidTa



	if @DataType='tasfienashode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande=SumDaryafti
		end

	--بروزرساني تلفن
	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #tmpDaryaftTasfie4  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin				
					update #tmpDaryaftTasfie4  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 #tmpDaryaftTasfie4  set Adress =tbl9.fldAddress from
		(Select fldAddress,fldCodeTafzili from tblTafzili) as tbl9			
		where #tmpDaryaftTasfie4.fldCodeTafzili=tbl9.fldCodeTafzili

	set @sumMandeTasfieNashode=(Select Sum(fldmandeTasfienashode) as SumMande from #tmpDaryaftTasfie4)
	if @sumMandeTasfieNashode is null
		set @sumMandeTasfieNashode=0




	
			Select codeTafzili,SharheTafzili,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,	
			Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4			
				order by fldDateSarResid,fldShomareFactor
		


END
GO

-- ===============================================
-- SP: [dbo].[ListeFactorhayeTasfieNashodeFordaryaft]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeFactorhayeTasfieNashodeFordaryaft', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeFactorhayeTasfieNashodeFordaryaft] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeFactorhayeTasfieNashodeFordaryaft] 
	@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) COLLATE Persian_100_CI_AS,
	[fldMablagheFactor][bigint],
	[fldMablagheMande][bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,
	[fldMablagheDaryaftiJari] [bigint],
	[fldDateSarResid][bigint],
	[ShomareDaryaft][bigint],
	[fldMablagheBargashti][bigint],
	[fldTakhfif] bigint,
	[fldDaryaftKolOnly] bigint,
	[fldmandeTasfienashode] [bigint],
	[fldCodeVasete] bigint,
	[fldNameVasete][nvarchar](100) COLLATE Persian_100_CI_AS
	)

	--insert into #tmpDaryaftTasfie2
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
		


	insert into #tmpDaryaftTasfie2
		(fldShomareFactor,SumDaryafti,fldCodeTafzili,fldMablaghefactor,fldMablagheMande,fldSharh,fldDateSarResid,fldTakhfif)
		Select fldShomareFactor,0,fldCodeTafzili,fldMablagheFactor, fldMablagheMandeFactor,fldSharh,fldDateSarResid,fldtakhfif
			from tblTasfie
			where fldCodeTafzili = @CodeTafzili and fldBastan is NULL

	update #tmpDaryaftTasfie2
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareBargashtAzForoosh=0 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






		update #tmpDaryaftTasfie2
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie2.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie2.fldShomareFactor=tbl1.fldShomareFactor

		update #tmpDaryaftTasfie2
		set fldTakhfif=tbl1.sumTakhfif from		
		(Select fldShomareFactor, isnull(Sum(fldTakhfif),0) as sumTakhfif from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie2.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie2.fldShomareFactor=tbl1.fldShomareFactor
	
	--بروزرساني جمع مبلغ برگشتي bm
	update #tmpDaryaftTasfie2
	set fldMablagheBargashti=tbl11.fldMablagheBargashti from
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as fldMablagheBargashti from tblRizeTasfie where fldShomareBargashtAzForoosh<>0 group by fldShomareFactor ) as tbl11
		where #tmpDaryaftTasfie2.fldShomareFactor=tbl11.fldShomareFactor

	update #tmpDaryaftTasfie2 set fldMablagheBargashti=0 where fldMablagheBargashti is null 

	update   #tmpDaryaftTasfie2 set SumDaryafti=SumDaryafti -- - fldMablagheBargashti

	update   #tmpDaryaftTasfie2 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti - fldMablagheBargashti



	update #tmpDaryaftTasfie2
		set fldDaryaftKolOnly=sumDaryafti+(fldMablaghefactor-fldMablagheMande)-fldTakhfif


	update #tmpDaryaftTasfie2 set fldCodeVasete=tbl1.fldCodeVasete from 
		(select distinct fldCodeVasete,fldShomareFactor from tblrizeforoosh where fldCodeTafsili=@CodeTafzili) as tbl1
		where tbl1.fldShomareFactor=#tmpDaryaftTasfie2.fldShomareFactor

	update #tmpDaryaftTasfie2 set fldNameVasete=tbl1.fldSharheTafzili from 
		(select fldCodeTafzili,fldSharheTafzili from tblTafzili ) as tbl1
		where tbl1.fldCodeTafzili=#tmpDaryaftTasfie2.fldCodeVasete

	Select fldShomareFactor,SumDaryafti,fldMablagheFactor, 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,fldMablagheBargashti,fldtakhfif,fldDaryaftKolOnly,fldmandeTasfienashode,fldCodeVasete,fldNameVasete
		from #tmpDaryaftTasfie2
			where fldMablagheMande>(SumDaryafti+fldMablagheBargashti) or fldMablagheDaryaftiJari>0
		order by fldDateSarResid,fldShomareFactor

END
GO

-- ===============================================
-- SP: [dbo].[ListeFactorhayeTasfieNashodeReport]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeFactorhayeTasfieNashodeReport', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeFactorhayeTasfieNashodeReport] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeFactorhayeTasfieNashodeReport] 
	@ListGroupAshkhas varchar(5000)=null ,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeVisitor varchar(5000)=null,
	@CodeTafzili nvarchar(10),		
	@DataType varchar(40),
	@DateSarResidAz bigint,
	@DateSarResidTa bigint,
	@DateFactorAz bigint,
	@DateFactorTa bigint,
	@FlagSort Varchar(15),
	@SumFactorha bigint output,
	@SumMandeFactor bigint output,
	@SumMandeTasfieNashode bigint output,
	@SumKoleDaryafti bigint output
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie4(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheFactor][bigint],
	[fldMablagheMande][bigint],
	[fldMablagheBargashti][bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,	
	[fldDateSarResid][bigint],
	[fldDateFactor][bigint],
	[ShomareDaryaft][bigint],
	[SharheTafzili][nvarchar](200) COLLATE Persian_100_CI_AS,
	[codeTafzili][nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldCodeGroupAshkhas][bigint],
	[NameGroup][nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldCodeVasete][bigint],
	[NameVasete][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Tell][nvarchar](50) COLLATE Persian_100_CI_AS,
	[Adress][nvarchar](200) COLLATE Persian_100_CI_AS

	)

	--insert into #tmpDaryaftTasfie4
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
		
	
	
	insert into #tmpDaryaftTasfie4
			(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
			Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor, fldMablagheMandeFactor,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
				from  dbo.tblTasfie INNER JOIN
				dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor   where  tblRizeForoosh.fldType<>'amani'

		if @Codetafzili<>0 --يعني همه افراد
			delete #tmpDaryaftTasfie4 where fldCodeTafzili<>@CodeTafzili

	update #tmpDaryaftTasfie4
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor
	
	--بروزرساني جمع مبلغ برگشتي bm
	update #tmpDaryaftTasfie4
	set fldMablagheBargashti=tbl11.fldMablagheBargashti from
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as fldMablagheBargashti from tblRizeTasfie where fldShomareBargashtAzForoosh<>0 group by fldShomareFactor ) as tbl11
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl11.fldShomareFactor

		
	
	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor

	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	update   #tmpDaryaftTasfie4 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti - fldMablagheBargashti

	--بروزرساني کد تفصيلي
	update #tmpDaryaftTasfie4 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl3.fldShomareFactorForoosh

	--بروزرساني نام تفصيلي
	update #tmpDaryaftTasfie4 set SharheTafzili=tbl5.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl5
		where #tmpDaryaftTasfie4.codeTafzili=tbl5.fldCodeTafzili

	--بروزرساني کدگروه 
	update #tmpDaryaftTasfie4 set fldCodeGroupAshkhas=tbl6.fldCodeGroup from
		(Select fldCodeGroup,fldCodeTafzili from tblTafzili) as tbl6
		Where #tmpDaryaftTasfie4.fldCodeTafzili=tbl6.fldCodeTafzili
	
	--بروزرساني نام گروه
	update #tmpDaryaftTasfie4  set NameGroup=tbl6.fldGroupName from
		(Select fldGroupId,fldGroupName from tblGroupAshkhas) as tbl6
		where tbl6.fldGroupId=#tmpDaryaftTasfie4.fldCodeGroupAshkhas
	

	--بروزرساني کد ويزيتورها	
	update #tmpDaryaftTasfie4  set fldCodeVasete = tbl7.fldCodeVasete from
		(SELECT        tblForoosh.fldShomareFactorForoosh, tblRizeForoosh.fldCodeVasete
			FROM            tblForoosh INNER JOIN
							 tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl7
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl7.fldShomareFactorForoosh

	--بروزرساني نام ويزيتورها
	update #tmpDaryaftTasfie4  set NameVasete=tbl8.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl8
		where #tmpDaryaftTasfie4.fldCodeVasete=tbl8.fldCodeTafzili  and fldCodeVasete<>0
	
	update #tmpDaryaftTasfie4 set NameVasete='' where fldCodeVasete=0

	--بروزرساني تاريخ سررسيد bm
	update #tmpDaryaftTasfie4 set fldDateSarResid=tbl9.fldDateSarResid from
	(select fldDateSarResid,fldShomareFactor from tblTasfie) as tbl9
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl9.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateSarResid< @DateSarResidAz
		delete #tmpDaryaftTasfie4 Where fldDateSarResid> @DateSarResidTa
	--بروزرساني تاريخ فاکتور bm
	update #tmpDaryaftTasfie4 set fldDateFactor=tbl10.fldDate from
	(select fldDate,fldShomareFactor from tblRizeForoosh) as tbl10
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl10.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateFactor< @DateFactorAz
		delete #tmpDaryaftTasfie4 Where fldDateFactor> @DateFactorTa

	 if @ListCodeAshkhas <>''
		begin
			declare @StrDeleteAshkhas varchar(5000)
			set  @StrDeleteAshkhas='delete from #tmpDaryaftTasfie4 
				where fldCodeTafzili NOT IN ('+ @ListCodeAshkhas +')'
				execute(@StrDeleteAshkhas)
		end


		if @ListGroupAshkhas<>''
			begin
			declare @StrDeleteGroupAshkhas varchar(5000)
			set  @StrDeleteGroupAshkhas='delete from #tmpDaryaftTasfie4 
				where '+ @ListGroupAshkhas + ''
				execute(@StrDeleteGroupAshkhas)
			end


		if @ListCodeVisitor<>''
			begin
				if @ListCodeVisitor='-1' --ليست فاکتورهاي بدون ويزيتور
					begin
						delete from #tmpDaryaftTasfie4 where fldCodeVasete<>0
					end
				else
					begin
					declare @StrDeleteVisitor varchar(5000)
					set  @StrDeleteVisitor='delete from #tmpDaryaftTasfie4 
						where '+ @ListCodeVisitor + ''
						execute(@StrDeleteVisitor)
					end
			end


	if @DataType='tasfienashode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande=(SumDaryafti+fldMablagheBargashti)
		end
	if @DataType='tasfieshode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande<>(SumDaryafti+fldMablagheBargashti)
		end
	--بروزرساني تلفن
	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #tmpDaryaftTasfie4  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin				
					update #tmpDaryaftTasfie4  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 #tmpDaryaftTasfie4  set Adress =tbl9.fldAddress from
		(Select fldAddress,fldCodeTafzili from tblTafzili) as tbl9			
		where #tmpDaryaftTasfie4.fldCodeTafzili=tbl9.fldCodeTafzili

	set @sumMandeTasfieNashode=(Select Sum(fldmandeTasfienashode) as SumMande from #tmpDaryaftTasfie4)
	if @sumMandeTasfieNashode is null
		set @sumMandeTasfieNashode=0

	set @SumFactorha=(Select Sum(fldMablagheFactor) as SumMande from #tmpDaryaftTasfie4)
	if @SumFactorha is null
		set @SumFactorha=0

	set @SumMandeFactor=(Select Sum(fldMablagheMande) as SumMande from #tmpDaryaftTasfie4)
	if @SumMandeFactor is null
		set @SumMandeFactor=0


	set @SumKoleDaryafti=(Select Sum(SumDaryafti) as SumMande from #tmpDaryaftTasfie4)
	if @SumKoleDaryafti is null
		set @SumKoleDaryafti=0

	


	if @FlagSort='date'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2)  as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameVasete,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0
				order by fldDateSarResid,fldShomareFactor
		
	if @FlagSort='factor'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameVasete,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by fldShomareFactor,fldDateSarResid
	
	if @FlagSort='bk'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameVasete,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0		
				order by fldmandeTasfienashode desc--,fldShomareFactor,fldDateSarResid

	if @FlagSort='kb'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
				NameVasete,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by Convert(bigint,fldmandeTasfienashode) asc--,fldShomareFactor,fldDateSarResid

	else if @FlagSort='nameshakhs'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
			substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameVasete,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by SharheTafzili asc,fldShomareFactor,fldDateSarResid

	else if @FlagSort='namegorooh'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameVasete,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameGroup asc,fldShomareFactor,fldDateSarResid

	else --@FlagSort='namevizitor'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameVasete,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			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 #tmpDaryaftTasfie4' + @order			


END
GO

-- ===============================================
-- SP: [dbo].[ListeFactorhayeTasfieNashodeReport_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeFactorhayeTasfieNashodeReport_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeFactorhayeTasfieNashodeReport_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeFactorhayeTasfieNashodeReport_WithUserCode] 
	@ListGroupAshkhas varchar(5000)=null ,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeVisitor varchar(5000)=null,
	@CodeTafzili nvarchar(10),		
	@DataType varchar(40),
	@DateSarResidAz bigint,
	@DateSarResidTa bigint,
	@DateFactorAz bigint,
	@DateFactorTa bigint,
	@FlagSort Varchar(15),
	@SumFactorha bigint output,
	@SumMandeFactor bigint output,
	@SumMandeTasfieNashode bigint output,
	@SumKoleDaryafti bigint output,
	@userCode bigint
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie4(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheFactor][bigint],
	[fldtakhfif] decimal(18,0),
	[fldMablagheMande][bigint],
	[fldMablagheBargashti][bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,	
	[fldDateSarResid][bigint],
	[fldDateFactor][bigint],
	[ShomareDaryaft][bigint],
	[SharheTafzili][nvarchar](200) COLLATE Persian_100_CI_AS,
	[codeTafzili][nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldCodeGroupAshkhas][bigint],
	[NameGroup][nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldCodeVasete][bigint],
	[NameVasete][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Tell][nvarchar](50) COLLATE Persian_100_CI_AS,
	[Adress][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Sharh] [nvarchar](70) COLLATE Persian_100_CI_AS,
	[color] int
	)

	--insert into #tmpDaryaftTasfie4
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
	update tblTasfie set fldsanad=tblForoosh.fldShomareSanad from tblForoosh where tblTasfie.fldShomareFactor = tblForoosh.fldShomareFactorForoosh
	update tblTasfie set fldTakhfif=tbl1.fldbedehkar from  (select fldbedehkar,fldSanad from tblSodooreSanad where fldMoinKamel='61202') as tbl1  where tblTasfie.fldSanad=tbl1.fldsanad
	update tblRizeTasfie set fldsanad=tblDaryaft.fldShomareSanad from tblDaryaft where tblRizeTasfie.fldShomareDaryaft= tblDaryaft.fldShomareDaryaft
	update tblRizeTasfie set fldTakhfif=tbl1.fldbedehkar from  (select fldbedehkar,fldSanad from tblSodooreSanad where fldMoinKamel='61202') as tbl1  where tblRizeTasfie.fldSanad=tbl1.fldsanad

	update tbltasfie set fldTakhfif=0 where fldTakhfif is NULL
	update tblRizeTasfie set fldTakhfif=0 where fldTakhfif is NULL
	
	if @DataType='bastan'
		insert into #tmpDaryaftTasfie4
				(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldtakhfif,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
				Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor,fldtakhfif, fldMablagheMandeFactor,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
					from  dbo.tblTasfie INNER JOIN
					dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor where fldBastan is not NUll
	else if @DataType='all'
		insert into #tmpDaryaftTasfie4
				(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldtakhfif,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
				Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor,fldtakhfif, fldMablagheMandeFactor,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
					from  dbo.tblTasfie INNER JOIN
					dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor 
	else
		insert into #tmpDaryaftTasfie4
				(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldtakhfif,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
				Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor,fldtakhfif, fldMablagheMandeFactor,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
					from  dbo.tblTasfie INNER JOIN
					dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor where fldBastan is NUll

		if @Codetafzili<>0 --يعني همه افراد
			delete #tmpDaryaftTasfie4 where fldCodeTafzili<>@CodeTafzili


--update #tmpDaryaftTasfie4 set sharh='mmm'
--update #tmpDaryaftTasfie4 set color=6
update #tmpDaryaftTasfie4 set  #tmpDaryaftTasfie4.color=tblSharheFactorTasfie.fldColor,sharh=tblSharheFactorTasfie.fldSharh   from tblSharheFactorTasfie where #tmpDaryaftTasfie4.fldShomareFactor=tblSharheFactorTasfie.fldshomarefactor

	update #tmpDaryaftTasfie4
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor

	update #tmpDaryaftTasfie4
		set fldtakhfif=fldtakhfif+tbl1.sumTakhfif from		
		(Select fldShomareFactor, isnull(Sum(fldtakhfif),0) as sumTakhfif from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor
	
	--بروزرساني جمع مبلغ برگشتي bm
	update #tmpDaryaftTasfie4
	set fldMablagheBargashti=tbl11.fldMablagheBargashti from
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as fldMablagheBargashti from tblRizeTasfie where fldShomareBargashtAzForoosh<>0 group by fldShomareFactor ) as tbl11
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl11.fldShomareFactor

		
	
	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor

	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	update   #tmpDaryaftTasfie4 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti - fldMablagheBargashti

	--بروزرساني کد تفصيلي
	update #tmpDaryaftTasfie4 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl3.fldShomareFactorForoosh

	--بروزرساني نام تفصيلي
	update #tmpDaryaftTasfie4 set SharheTafzili=tbl5.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl5
		where #tmpDaryaftTasfie4.codeTafzili=tbl5.fldCodeTafzili

	--بروزرساني کدگروه 
	update #tmpDaryaftTasfie4 set fldCodeGroupAshkhas=tbl6.fldCodeGroup from
		(Select fldCodeGroup,fldCodeTafzili from tblTafzili) as tbl6
		Where #tmpDaryaftTasfie4.fldCodeTafzili=tbl6.fldCodeTafzili
	
	--بروزرساني نام گروه
	update #tmpDaryaftTasfie4  set NameGroup=tbl6.fldGroupName from
		(Select fldGroupId,fldGroupName from tblGroupAshkhas) as tbl6
		where tbl6.fldGroupId=#tmpDaryaftTasfie4.fldCodeGroupAshkhas
	

	--بروزرساني کد ويزيتورها	
	update #tmpDaryaftTasfie4  set fldCodeVasete = tbl7.fldCodeVasete from
		(SELECT        tblForoosh.fldShomareFactorForoosh, tblRizeForoosh.fldCodeVasete
			FROM            tblForoosh INNER JOIN
							 tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl7
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl7.fldShomareFactorForoosh

	--بروزرساني نام ويزيتورها
	update #tmpDaryaftTasfie4  set NameVasete=tbl8.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl8
		where #tmpDaryaftTasfie4.fldCodeVasete=tbl8.fldCodeTafzili  and fldCodeVasete<>0
	
	update #tmpDaryaftTasfie4 set NameVasete='' where fldCodeVasete=0

	--بروزرساني تاريخ سررسيد bm
	update #tmpDaryaftTasfie4 set fldDateSarResid=tbl9.fldDateSarResid from
	(select fldDateSarResid,fldShomareFactor from tblTasfie) as tbl9
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl9.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateSarResid< @DateSarResidAz
		delete #tmpDaryaftTasfie4 Where fldDateSarResid> @DateSarResidTa
	--بروزرساني تاريخ فاکتور bm
	update #tmpDaryaftTasfie4 set fldDateFactor=tbl10.fldDate from
	(select fldDate,fldShomareFactor from tblRizeForoosh) as tbl10
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl10.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateFactor< @DateFactorAz
		delete #tmpDaryaftTasfie4 Where fldDateFactor> @DateFactorTa

	 if @ListCodeAshkhas <>''
		begin
			declare @StrDeleteAshkhas varchar(5000)
			set  @StrDeleteAshkhas='delete from #tmpDaryaftTasfie4 
				where fldCodeTafzili NOT IN ('+ @ListCodeAshkhas +')'
				execute(@StrDeleteAshkhas)
		end


		if @ListGroupAshkhas<>''
			begin
			declare @StrDeleteGroupAshkhas varchar(5000)
			set  @StrDeleteGroupAshkhas='delete from #tmpDaryaftTasfie4 
				where '+ @ListGroupAshkhas + ''
				execute(@StrDeleteGroupAshkhas)
			end


		if @ListCodeVisitor<>''
			begin
				if @ListCodeVisitor='-1' --ليست فاکتورهاي بدون ويزيتور
					begin
						delete from #tmpDaryaftTasfie4 where fldCodeVasete<>0
					end
				else
					begin
					declare @StrDeleteVisitor varchar(5000)
					set  @StrDeleteVisitor='delete from #tmpDaryaftTasfie4 
						where '+ @ListCodeVisitor + ''
						execute(@StrDeleteVisitor)
					end
			end


	if @DataType='tasfienashode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande=(SumDaryafti+fldMablagheBargashti)
		end
	if @DataType='tasfieshode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande<>(SumDaryafti+fldMablagheBargashti)
		end
	--بروزرساني تلفن
	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #tmpDaryaftTasfie4  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin				
					update #tmpDaryaftTasfie4  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 #tmpDaryaftTasfie4  set Adress =tbl9.fldAddress from
		(Select fldAddress,fldCodeTafzili from tblTafzili) as tbl9			
		where #tmpDaryaftTasfie4.fldCodeTafzili=tbl9.fldCodeTafzili



-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################
-- ##########################################################

-- ##################### Group Ashkhas Limitation
-- ##########################################################


delete from #tmpDaryaftTasfie4 where
fldCodeTafzili not in (select code from @accessCodes)
-- ##########################################################

	set @sumMandeTasfieNashode=(Select Sum(fldmandeTasfienashode) as SumMande from #tmpDaryaftTasfie4)
	if @sumMandeTasfieNashode is null
		set @sumMandeTasfieNashode=0

	set @SumFactorha=(Select Sum(fldMablagheFactor) as SumMande from #tmpDaryaftTasfie4)
	if @SumFactorha is null
		set @SumFactorha=0

	set @SumMandeFactor=(Select Sum(fldMablagheMande) as SumMande from #tmpDaryaftTasfie4)
	if @SumMandeFactor is null
		set @SumMandeFactor=0


	set @SumKoleDaryafti=(Select Sum(SumDaryafti) as SumMande from #tmpDaryaftTasfie4)
	if @SumKoleDaryafti is null
		set @SumKoleDaryafti=0

--update #tmpDaryaftTasfie4 set  #tmpDaryaftTasfie4.color=tblSharheFactorTasfie.fldColor,sharh=tblSharheFactorTasfie.fldSharh   from tblSharheFactorTasfie where #tmpDaryaftTasfie4.fldShomareFactor=tblSharheFactorTasfie.fldshomarefactor

--جداسازی مبلغ تخفیف و دریافت
--                                        جمع دریافت طی دوره + جمع تسویه فاکتور-جمع تخفیف کل
update #tmpDaryaftTasfie4 set SumDaryafti=SumDaryafti + (fldMablagheFactor-fldMablagheMande) -fldtakhfif
	if @FlagSort='date'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldtakhfif,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2)  as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameVasete,Tell,Adress,fldSharh,color,Sharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0
				order by fldDateSarResid,fldShomareFactor
		
	if @FlagSort='factor'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldtakhfif,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameVasete,Tell,Adress,fldSharh,color,Sharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by fldShomareFactor,fldDateSarResid
	
	if @FlagSort='bk'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldtakhfif,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameVasete,Tell,Adress,fldSharh,color,Sharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0		
				order by fldmandeTasfienashode desc--,fldShomareFactor,fldDateSarResid

	if @FlagSort='kb'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldtakhfif,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
				NameVasete,Tell,Adress,fldSharh,color,Sharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by Convert(bigint,fldmandeTasfienashode) asc--,fldShomareFactor,fldDateSarResid

	else if @FlagSort='nameshakhs'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldtakhfif,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
			substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameVasete,Tell,Adress,fldSharh,color,Sharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by SharheTafzili asc,fldShomareFactor,fldDateSarResid

	else if @FlagSort='namegorooh'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldtakhfif,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameVasete,Tell,Adress,fldSharh,color,Sharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameGroup asc,fldShomareFactor,fldDateSarResid

	else --@FlagSort='namevizitor'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldtakhfif,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameVasete,Tell,Adress,fldSharh,color,Sharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			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 #tmpDaryaftTasfie4' + @order			


END
GO

-- ===============================================
-- SP: [dbo].[ListeFactorhayeTasfieNashodeReportAlarm_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeFactorhayeTasfieNashodeReportAlarm_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeFactorhayeTasfieNashodeReportAlarm_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeFactorhayeTasfieNashodeReportAlarm_WithUserCode] 
	@CodeTafzili nvarchar(10),		
	@DataType varchar(40),
	@DateSarResidAz bigint,
	@DateSarResidTa bigint,
	@SumMandeTasfieNashode bigint output
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie4(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheFactor][bigint],
	[fldtakhfif] decimal(18,0),
	[fldMablagheMande][bigint],
	[fldMablagheBargashti][bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,	
	[fldDateSarResid][bigint],
	[fldDateFactor][bigint],
	[ShomareDaryaft][bigint],
	[SharheTafzili][nvarchar](200) COLLATE Persian_100_CI_AS,
	[codeTafzili][nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldCodeGroupAshkhas][bigint],
	[NameGroup][nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldCodeVasete][bigint],
	[NameVasete][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Tell][nvarchar](50) COLLATE Persian_100_CI_AS,
	[Adress][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Sharh] [nvarchar](70) COLLATE Persian_100_CI_AS,
	[color] int
	)

	--insert into #tmpDaryaftTasfie4
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
	update tblTasfie set fldsanad=tblForoosh.fldShomareSanad from tblForoosh where tblTasfie.fldShomareFactor = tblForoosh.fldShomareFactorForoosh
	update tblTasfie set fldTakhfif=tbl1.fldbedehkar from  (select fldbedehkar,fldSanad from tblSodooreSanad where fldMoinKamel='61202') as tbl1  where tblTasfie.fldSanad=tbl1.fldsanad
	update tblRizeTasfie set fldsanad=tblDaryaft.fldShomareSanad from tblDaryaft where tblRizeTasfie.fldShomareDaryaft= tblDaryaft.fldShomareDaryaft
	update tblRizeTasfie set fldTakhfif=tbl1.fldbedehkar from  (select fldbedehkar,fldSanad from tblSodooreSanad where fldMoinKamel='61202') as tbl1  where tblRizeTasfie.fldSanad=tbl1.fldsanad

	update tbltasfie set fldTakhfif=0 where fldTakhfif is NULL
	update tblRizeTasfie set fldTakhfif=0 where fldTakhfif is NULL
	
	if @DataType='bastan'
		insert into #tmpDaryaftTasfie4
				(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldtakhfif,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
				Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor,fldtakhfif, fldMablagheMandeFactor,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
					from  dbo.tblTasfie INNER JOIN
					dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor where fldBastan is not NUll
	else if @DataType='all'
		insert into #tmpDaryaftTasfie4
				(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldtakhfif,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
				Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor,fldtakhfif, fldMablagheMandeFactor,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
					from  dbo.tblTasfie INNER JOIN
					dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor 
	else if @DataType='bazbaste'
		insert into #tmpDaryaftTasfie4				
				(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldtakhfif,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
				Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor,fldtakhfif, fldMablagheMandeFactor,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
					from  dbo.tblTasfie INNER JOIN
					dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor  where fldBastan is NUll
	else if @DataType='basteno'
			insert into #tmpDaryaftTasfie4
				(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldtakhfif,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
				Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor,fldtakhfif, fldMablagheMandeFactor,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
					from  dbo.tblTasfie INNER JOIN
					dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor where fldBastan is  NUll
	else
		insert into #tmpDaryaftTasfie4
				(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldtakhfif,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
				Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor,fldtakhfif, fldMablagheMandeFactor,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
					from  dbo.tblTasfie INNER JOIN
					dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor where fldBastan is NUll

		if @Codetafzili<>0 --يعني همه افراد
			delete #tmpDaryaftTasfie4 where fldCodeTafzili<>@CodeTafzili


--update #tmpDaryaftTasfie4 set sharh='mmm'
--update #tmpDaryaftTasfie4 set color=6
update #tmpDaryaftTasfie4 set  #tmpDaryaftTasfie4.color=tblSharheFactorTasfie.fldColor,sharh=tblSharheFactorTasfie.fldSharh   from tblSharheFactorTasfie where #tmpDaryaftTasfie4.fldShomareFactor=tblSharheFactorTasfie.fldshomarefactor

	update #tmpDaryaftTasfie4
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor

	update #tmpDaryaftTasfie4
		set fldtakhfif=fldtakhfif+tbl1.sumTakhfif from		
		(Select fldShomareFactor, isnull(Sum(fldtakhfif),0) as sumTakhfif from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor
	
	--بروزرساني جمع مبلغ برگشتي bm
	update #tmpDaryaftTasfie4
	set fldMablagheBargashti=tbl11.fldMablagheBargashti from
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as fldMablagheBargashti from tblRizeTasfie where fldShomareBargashtAzForoosh<>0 group by fldShomareFactor ) as tbl11
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl11.fldShomareFactor

		
	
	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor

	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	update   #tmpDaryaftTasfie4 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti - fldMablagheBargashti

	--بروزرساني کد تفصيلي
	update #tmpDaryaftTasfie4 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl3.fldShomareFactorForoosh

	--بروزرساني نام تفصيلي
	update #tmpDaryaftTasfie4 set SharheTafzili=tbl5.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl5
		where #tmpDaryaftTasfie4.codeTafzili=tbl5.fldCodeTafzili

	--بروزرساني کدگروه 
	update #tmpDaryaftTasfie4 set fldCodeGroupAshkhas=tbl6.fldCodeGroup from
		(Select fldCodeGroup,fldCodeTafzili from tblTafzili) as tbl6
		Where #tmpDaryaftTasfie4.fldCodeTafzili=tbl6.fldCodeTafzili
	
	--بروزرساني نام گروه
	update #tmpDaryaftTasfie4  set NameGroup=tbl6.fldGroupName from
		(Select fldGroupId,fldGroupName from tblGroupAshkhas) as tbl6
		where tbl6.fldGroupId=#tmpDaryaftTasfie4.fldCodeGroupAshkhas
	

	--بروزرساني کد ويزيتورها	
	update #tmpDaryaftTasfie4  set fldCodeVasete = tbl7.fldCodeVasete from
		(SELECT        tblForoosh.fldShomareFactorForoosh, tblRizeForoosh.fldCodeVasete
			FROM            tblForoosh INNER JOIN
							 tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl7
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl7.fldShomareFactorForoosh

	--بروزرساني نام ويزيتورها
	update #tmpDaryaftTasfie4  set NameVasete=tbl8.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl8
		where #tmpDaryaftTasfie4.fldCodeVasete=tbl8.fldCodeTafzili  and fldCodeVasete<>0
	
	update #tmpDaryaftTasfie4 set NameVasete='' where fldCodeVasete=0

	--بروزرساني تاريخ سررسيد bm
	update #tmpDaryaftTasfie4 set fldDateSarResid=tbl9.fldDateSarResid from
	(select fldDateSarResid,fldShomareFactor from tblTasfie) as tbl9
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl9.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateSarResid< @DateSarResidAz
		delete #tmpDaryaftTasfie4 Where fldDateSarResid> @DateSarResidTa
	--بروزرساني تاريخ فاکتور bm
	update #tmpDaryaftTasfie4 set fldDateFactor=tbl10.fldDate from
	(select fldDate,fldShomareFactor from tblRizeForoosh) as tbl10
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl10.fldShomareFactor
		






	if @DataType='tasfienashode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande=(SumDaryafti+fldMablagheBargashti)
		end
	if @DataType='tasfieshode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande<>(SumDaryafti+fldMablagheBargashti)
		end
	--بروزرساني تلفن
	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #tmpDaryaftTasfie4  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin				
					update #tmpDaryaftTasfie4  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 #tmpDaryaftTasfie4  set Adress =tbl9.fldAddress from
		(Select fldAddress,fldCodeTafzili from tblTafzili) as tbl9			
		where #tmpDaryaftTasfie4.fldCodeTafzili=tbl9.fldCodeTafzili

	set @sumMandeTasfieNashode=(Select Sum(fldmandeTasfienashode) as SumMande from #tmpDaryaftTasfie4)
	if @sumMandeTasfieNashode is null
		set @sumMandeTasfieNashode=0






-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
-- ##########################################################
-- ##########################################################

-- ##################### Group Ashkhas Limitation
-- ##########################################################


-- ##########################################################
--update #tmpDaryaftTasfie4 set  #tmpDaryaftTasfie4.color=tblSharheFactorTasfie.fldColor,sharh=tblSharheFactorTasfie.fldSharh   from tblSharheFactorTasfie where #tmpDaryaftTasfie4.fldShomareFactor=tblSharheFactorTasfie.fldshomarefactor

--جداسازی مبلغ تخفیف و دریافت
--                                        جمع دریافت طی دوره + جمع تسویه فاکتور-جمع تخفیف کل
update #tmpDaryaftTasfie4 set SumDaryafti=SumDaryafti + (fldMablagheFactor-fldMablagheMande) -fldtakhfif
	
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldtakhfif,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2)  as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameVasete,Tell,Adress,fldSharh,color,Sharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0
				order by fldDateSarResid,fldShomareFactor
		
			


END
GO

-- ===============================================
-- SP: [dbo].[ListeKalaDynamic]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeKalaDynamic', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeKalaDynamic] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ListeKalaDynamic] 
	@CodeGroupKala varchar(5000),
	@sort nvarchar(20)
AS
BEGIN


create Table #temp1
(
	fldCodeKala bigint,
	fldNamekala nvarchar(200) COLLATE Persian_100_CI_AS,
	fldCodeGroup bigint,
	fldNameGroup nvarchar(200) COLLATE Persian_100_CI_AS,
	fldFee1 decimal(18,4),
	fldFee2 decimal(18,4),
	fldFee3 decimal(18,4),
	fldFee4 decimal(18,4),
	fldFee5 decimal(18,4),
	fldFee6 decimal(18,4),
	fldCodeSharh1 bigint,
	fldCodeSharh2 bigint,
	fldCodeSharh3 bigint,
	fldCodeSharh4 bigint,
	fldCodeSharh5 bigint,
	fldCodeSharh6 bigint,
	fldSharhFee1 nvarchar(200) COLLATE Persian_100_CI_AS,	
	fldSharhFee2 nvarchar(200) COLLATE Persian_100_CI_AS,
	fldSharhFee3 nvarchar(200) COLLATE Persian_100_CI_AS,
	fldSharhFee4 nvarchar(200) COLLATE Persian_100_CI_AS,
	fldSharhFee5 nvarchar(200) COLLATE Persian_100_CI_AS,
	fldSharhFee6 nvarchar(200) COLLATE Persian_100_CI_AS,
	fldGheimatMasrafkonande decimal(18,4),
	fldCodeVahed1       varchar(100) COLLATE Persian_100_CI_AS,
	fldCodeVahed2       varchar(100) COLLATE Persian_100_CI_AS, 
	fldNameVahed1       nvarchar(100) COLLATE Persian_100_CI_AS, 
	FldNameVahed2       nvarchar(100) COLLATE Persian_100_CI_AS
)

create Table #tempOrder
(
Row1 bigint,
fldCodeSharh bigint,
fldFee decimal(18,4),
fldCodeKala bigint,
)

insert into #temporder
	(Row1,fldCodeSharh,fldFee,fldCodeKala)			
(SELECT 
   ROW_NUMBER() OVER (partition by fldCodeKala order by fldCodeKala,fldCodeSharh)  RowNo,fldCodeSharh ,fldfee,fldCodeKala    
FROM 
   tblMultiFeeDynamic)



insert into #temp1
	(fldCodeKala,fldFee1,fldfee2,fldfee3,fldfee4,fldfee5,fldfee6,fldCodeSharh1,fldCodeSharh2,fldCodeSharh3,fldCodeSharh4,fldCodeSharh5,fldCodeSharh6)
   SELECT DISTINCT fldCodeKala
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=1) AS Fee1
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=2) AS Fee2
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=3) AS Fee3
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=4) AS Fee4
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=5) AS Fee5
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=6) AS Fee6
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=1) AS fldCodeSharh1
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=2) AS fldCodeSharh2
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=3) AS fldCodeSharh3
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=4) AS fldCodeSharh4
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=5) AS fldCodeSharh5
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=6) AS fldCodeSharh6
FROM #tempOrder s1

	--create table #TempListKala1(
	--fldNameKala         nvarchar(300) COLLATE Persian_100_CI_AS, 
	--fldCodeKala         bigint,
	--fldCodeVahed1       varchar(100) COLLATE Persian_100_CI_AS,
	--fldCodeVahed2       varchar(100) COLLATE Persian_100_CI_AS, 
	--fldNameVahed        nvarchar(100) COLLATE Persian_100_CI_AS, 
	--FldNameVahed2       nvarchar(100) COLLATE Persian_100_CI_AS,
	--fldCodeGroup        bigint,
	--fldGroupName        nvarchar(300) COLLATE Persian_100_CI_AS,
	--fldFeeForoosh1    decimal(18,4) , 
	--fldFeeForoosh2    decimal(18,4) , 
	--fldFeeForoosh3    decimal(18,4) , 
	--fldFeeForoosh4    decimal(18,4) , 
	--fldFeeForoosh5    decimal(18,4) , 
	--fldFeeForoosh6    decimal(18,4) , 
	--fldFeeForoosh7    decimal(18,4) , 
	--fldFeeForoosh8    decimal(18,4) )


	
	--insert into #TempListKala1(fldNameKala,fldCodeKala,fldCodeVahed1,fldCodeVahed2,fldNameVahed,FldNameVahed2,
	--						  fldCodeGroup,fldGroupName)
	--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
	--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


	


	update #temp1 set fldGheimatMasrafkonande =tblKala.fldGhymatMasrafkonande,fldNamekala=tblkala.fldNameKala,fldCodeGroup=tblKala.fldCodeGroup,fldCodeVahed1=tblKala.fldCodeVahed1,fldCodeVahed2=tblkala.fldCodeVahed2 from tblkala Where tblkala.fldCodekala=#temp1.fldCodeKala


	if @CodeGroupKala<>''
	begin
		declare @StrDeleteGroupKala varchar(5000)
		set  @StrDeleteGroupKala='delete from #temp1
			where '+ @CodeGroupKala + ''
			execute(@StrDeleteGroupKala)
	end


	update #temp1 set fldNameGroup=tblGroupKala.fldGroupName from tblGroupKala Where #temp1.fldCodeGroup=tblGroupKala.fldGroupId
	update #temp1 set fldNamevahed1=tblVahed.fldNameVahed from tblVahed Where fldCodeVahed1=tblVahed.ID
	update #temp1 set fldNamevahed2=tblVahed.fldNameVahed from tblVahed Where fldCodeVahed2=tblVahed.id

	update #temp1 set fldSharhFee1=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh1=tblSharheFeeDynamic.fldCodeSharh
	update #temp1 set fldSharhFee2=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh2=tblSharheFeeDynamic.fldCodeSharh
	update #temp1 set fldSharhFee3=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh3=tblSharheFeeDynamic.fldCodeSharh
	update #temp1 set fldSharhFee4=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh4=tblSharheFeeDynamic.fldCodeSharh
	update #temp1 set fldSharhFee5=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh5=tblSharheFeeDynamic.fldCodeSharh
	update #temp1 set fldSharhFee6=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh6=tblSharheFeeDynamic.fldCodeSharh

	if @sort='codekala'
		select 
		fldNameKala,       
		fldCodeKala,       
		fldCodeVahed1,      
		fldCodeVahed2,      
		fldNameVahed1,       
		FldNameVahed2,      
		fldCodeGroup,      
		fldNameGroup,       
		fldFee1,      
		fldFee2,      
		fldFee3,      
		fldFee4,      
		fldFee5,      
		fldFee6,      
		fldGheimatMasrafkonande,
		fldSharhFee1,
		fldSharhFee2,
		fldSharhFee3,
		fldSharhFee4,
		fldSharhFee5,
		fldSharhFee6
		from #temp1
		ORDER BY fldCodeKala Asc
	else if @sort='namekala'
			select 
		fldNameKala,       
		fldCodeKala,       
		fldCodeVahed1,      
		fldCodeVahed2,      
		fldNameVahed1,       
		FldNameVahed2,      
		fldCodeGroup,      
		fldNameGroup,       
		fldFee1,      
		fldFee2,      
		fldFee3,      
		fldFee4,      
		fldFee5,      
		fldFee6,      
		fldGheimatMasrafkonande,
		fldSharhFee1,
		fldSharhFee2,
		fldSharhFee3,
		fldSharhFee4,
		fldSharhFee5,
		fldSharhFee6
		from #temp1
		ORDER BY fldNameKala Asc


END
GO

-- ===============================================
-- SP: [dbo].[listekalamodat]
-- ===============================================
IF OBJECT_ID(N'dbo.listekalamodat', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[listekalamodat] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[listekalamodat]
--@NameHesab nvarChar(50),



as

begin
	--set @Meghdar=1020
	SELECT dbo.tblKala.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblKala.fldModat, dbo.tblGroupKala.fldGroupName, dbo.tblGroupKala.fldGroupId 
                     FROM dbo.tblKala 
                     INNER JOIN dbo.tblGroupKala ON dbo.tblKala.fldCodeGroup = dbo.tblGroupKala.fldGroupId

end
GO

-- ===============================================
-- SP: [dbo].[ListeTafzili_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeTafzili_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeTafzili_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeTafzili_WithUserCode] 
	@UserCode bigint
AS
BEGIN


update tbltafzili set fldcodegroup=100 where fldcodegroup is NULL

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 

	Select fldCodeTafzili,fldSharheTafzili,fldCodeNoe from tblTafzili
		where 
		fldCodeTafzili in (select code from @accessCodes) 
		order by Convert(dec,fldCodeTafzili)
END
GO

-- ===============================================
-- SP: [dbo].[ListeTafziliWithNoe]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeTafziliWithNoe', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeTafziliWithNoe] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeTafziliWithNoe] 
	@CodeNoe nvarchar(10)
AS
BEGIN
	Select fldCodeTafzili,fldSharheTafzili,fldCodeNoe from tblTafzili
		where fldCodeNoe=@CodeNoe
		order by Convert(dec,fldCodeTafzili)
END
GO

-- ===============================================
-- SP: [dbo].[ListeTafziliWithNoe_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ListeTafziliWithNoe_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ListeTafziliWithNoe_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ListeTafziliWithNoe_WithUserCode] 
	@CodeNoe nvarchar(10),
	@UserCode bigint
AS
BEGIN


update tbltafzili set fldcodegroup=100 where fldcodegroup is NULL

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 

	Select fldCodeTafzili,fldSharheTafzili,fldCodeNoe from tblTafzili
		where 
		fldCodeTafzili in (select code from @accessCodes) and 
		fldCodeNoe=@CodeNoe
		order by Convert(dec,fldCodeTafzili)
END
GO

-- ===============================================
-- SP: [dbo].[LoadPrinterOfKala]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadPrinterOfKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadPrinterOfKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[LoadShomareFishBeTafkikeChapger]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadShomareFishBeTafkikeChapger', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadShomareFishBeTafkikeChapger] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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) COLLATE Persian_100_CI_AS,
		fldSharhKala nvarchar(100) COLLATE Persian_100_CI_AS,
		fldTedadCarton nvarchar(10) COLLATE Persian_100_CI_AS,
		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) COLLATE Persian_100_CI_AS,	
		fldNameVahed2	nvarchar(100) COLLATE Persian_100_CI_AS,	
		fldNameAnbar nvarchar(50) COLLATE Persian_100_CI_AS,
		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

-- ===============================================
-- SP: [dbo].[LoadSuperVisor]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadSuperVisor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadSuperVisor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[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,(case when fldNoeMohasebePoorsant=1 then 'فروش' else 'واریز' end)  as fldSharheMohasebe,fldTel from tblTafzili Where fldCodeNoe='0' And fldNoeVizitor=1
END
GO

-- ===============================================
-- SP: [dbo].[LoadVaseteArshiveAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadVaseteArshiveAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadVaseteArshiveAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[LoadVaseteArshiveAmani] 
	-- 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

-- ===============================================
-- SP: [dbo].[LoadVaseteArshiveBargashtAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadVaseteArshiveBargashtAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadVaseteArshiveBargashtAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[LoadVaseteArshiveBargashtAmani] 
	-- 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        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

-- ===============================================
-- SP: [dbo].[LoadVaseteArshiveBargashtAzForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadVaseteArshiveBargashtAzForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadVaseteArshiveBargashtAzForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[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

-- ===============================================
-- SP: [dbo].[LoadVaseteArshiveForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadVaseteArshiveForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadVaseteArshiveForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[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     top(1)   fldCodeVasete
									FROM            dbo.tblRizeForoosh
										WHERE        (fldShomareSanad = @ShomareSanad)  )
	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

-- ===============================================
-- SP: [dbo].[LoadVaseteArshiveSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadVaseteArshiveSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadVaseteArshiveSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[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

-- ===============================================
-- SP: [dbo].[LoadVaseteArshiveSanadPardakht]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadVaseteArshiveSanadPardakht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadVaseteArshiveSanadPardakht] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[LoadVaseteArshiveSanadPardakht] 
	-- 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        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

-- ===============================================
-- SP: [dbo].[LoadVizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadVizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadVizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[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,(case when fldNoeMohasebePoorsant=1 then 'فروش' else 'واریز' end ) as fldSharheMohasebe from tblTafzili Where fldCodeNoe='0' And fldNoeVizitor=2
END
GO

-- ===============================================
-- SP: [dbo].[LoadVizitor2]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadVizitor2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadVizitor2] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[LoadVizitor2]
	-- Add the parameters for the stored procedure here
	
	
AS
BEGIN
	update tblTafzili set fldNoeMohasebePoorsant=0  where fldNoeMohasebePoorsant is null
	select tbl1.fldCodeTafzili , tbl1.fldSharheTafzili,tbl1.fldPoorsant,tbl1.ID,tbl1.fldCodeSuperVisor,tbl2.fldSharheTafzili as fldNameSuperVisor,tbl1.fldNoeMohasebePoorsant,iif(tbl1.fldNoeMohasebePoorsant=1,'فروش','واریز') as fldSharheMohasebe 
	from tblTafzili as tbl1 
	inner join tblTafzili as tbl2 on (tbl2.fldCodeTafzili=tbl1.fldCodeSuperVisor)
	Where tbl1.fldCodeNoe='0' And tbl1.fldNoeVizitor=2

END
GO

-- ===============================================
-- SP: [dbo].[LoadVizitorActiveunActive]
-- ===============================================
IF OBJECT_ID(N'dbo.LoadVizitorActiveunActive', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[LoadVizitorActiveunActive] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[LoadVizitorActiveunActive]

as 

begin

-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SELECT   dbo.tblTafzili.fldCodeTafzili, dbo.tblTafzili.fldSharheTafzili, dbo.tblTafzili.fldPoorsant, dbo.tblTafzili.fldNoeMohasebePoorsant,dbo.tblTafzili.fldSaghfeEtebar, 
                         CASE WHEN tblTafzili.fldNoeMohasebePoorsant = 1 THEN 'فروش' WHEN tblTafzili.fldNoeMohasebePoorsant = 2 THEN 'واریز' WHEN tblTafzili.fldNoeMohasebePoorsant = 3 THEN
                          'هدفمند' END AS fldSharheMohasebe, dbo.tblTafzili.fldCodeSuperVisor AS CodeSuperVisor, tblTafzili_1.fldSharheTafzili AS fldNameSuperVizor, dbo.tblTafzili.ID,case when dbo.tblTafzili.fldUnActive=1 then 'غیرفعال' when dbo.tblTafzili.fldUnActive=0 then 'فعال' end  as fldUnActiveShow ,dbo.tblTafzili.fldUnActive
				FROM         dbo.tblTafzili INNER JOIN
										 dbo.tblTafzili AS tblTafzili_1 ON dbo.tblTafzili.fldCodeSuperVisor = tblTafzili_1.fldCodeTafzili
				WHERE     (dbo.tblTafzili.fldNoeVizitor = 2) order by dbo.tblTafzili.fldUnActive 
	
end
GO

-- ===============================================
-- SP: [dbo].[MandeAnbarReport]
-- ===============================================
IF OBJECT_ID(N'dbo.MandeAnbarReport', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MandeAnbarReport] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[MandeAnbarReport]
	@CodeGroup bigint
as

begin
	Select * from tblKala Where fldCodeGroup=@CodeGroup
end
GO

-- ===============================================
-- SP: [dbo].[MandeKolTafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.MandeKolTafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MandeKolTafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[MandeTafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.MandeTafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MandeTafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[MandeTafziliBedehi]
-- ===============================================
IF OBJECT_ID(N'dbo.MandeTafziliBedehi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MandeTafziliBedehi] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[MaxAndMinShomareSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxAndMinShomareSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxAndMinShomareSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxAndMinShomareSanad]
	@Max bigint output,
	@min bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @Max=(select max(convert(bigint,fldsanad)) from tblSodooreSanad ) 
set @min=(select min(convert(bigint,fldsanad)) from tblSodooreSanad ) 



if @Max is null
	set @Max=0

if @min is null
	set @min=0

Return @Max
Return @min
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDate]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDate', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDate] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDate]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(flddate) from tblSodooreSanad) 
if @MaxDate is null
	set @MaxDate=0
set @minDate=(select min(flddate) from tblSodooreSanad) 
if @minDate is null	
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDate_RizeBargashtAzForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDate_RizeBargashtAzForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDate_RizeBargashtAzForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDate_RizeBargashtAzForoosh]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(flddate) from tblRizeBargashtAzForoosh) 
set @minDate=(select min(flddate) from tblRizeBargashtAzForoosh) 

if @MaxDate is null
	set @MaxDate=0

if @minDate is null
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDate_RizeBargashtAzKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDate_RizeBargashtAzKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDate_RizeBargashtAzKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDate_RizeBargashtAzKharid]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(flddate) from tblRizeBargashtAzKharid) 
set @minDate=(select min(flddate) from tblRizeBargashtAzKharid) 

if @MaxDate is null
	set @MaxDate=0

if @minDate is null
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDate_RizeKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDate_RizeKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDate_RizeKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDate_RizePishPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDate_RizePishPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDate_RizePishPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDate_RizePishPishForoosh]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(flddate) from tblRizePishPishForoosh) 
set @minDate=(select min(flddate) from tblRizePishPishForoosh) 

if @MaxDate is null
	set @MaxDate=0

if @minDate is null
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDateAmalkardKarbar]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDateAmalkardKarbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDateAmalkardKarbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDateAmalkardKarbar]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(Convert(dec,flddate)) from tblAmalkardekarbar where NoeAmaliat=N'جدید') 
set @minDate=(select min(Convert(dec,flddate)) from tblAmalkardekarbar where NoeAmaliat=N'جدید') 

if @MaxDate is null
	set @MaxDate=0

if @minDate is null
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDateDaramad]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDateDaramad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDateDaramad] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDateDaramad]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(Convert(dec,flddate)) from tblSodooreSanad where fldType='daramad') 
set @minDate=(select min(Convert(dec,flddate)) from tblSodooreSanad where fldType='daramad') 

if @MaxDate is null
	set @MaxDate=0

if @minDate is null
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDateDaryaft]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDateDaryaft', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDateDaryaft] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDateDaryaft]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(flddate) from tblSodooreSanad inner join dbo.tblDaryaft on dbo.tblDaryaft.fldShomareSanad=dbo.tblSodooreSanad.fldSanad
where dbo.tblDaryaft.fldType='Daryaft') 
if @MaxDate is null
	set @MaxDate=0
set @minDate=(select min(flddate) from tblSodooreSanad inner join dbo.tblDaryaft on dbo.tblDaryaft.fldShomareSanad=dbo.tblSodooreSanad.fldSanad
where dbo.tblDaryaft.fldType='Daryaft') 
if @minDate is null	
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDateForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDateForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDateForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDateForoosh]
	@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

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDateHazine]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDateHazine', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDateHazine] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDateHazine]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(Convert(dec,flddate)) from tblSodooreSanad where fldType='hazine') 
set @minDate=(select min(Convert(dec,flddate)) from tblSodooreSanad where fldType='hazine') 

if @MaxDate is null
	set @MaxDate=0

if @minDate is null
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDatePardakht]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDatePardakht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDatePardakht] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDatePardakht]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(flddate) from tblSodooreSanad inner join dbo.tblPardakht on dbo.tblPardakht.fldShomareSanad=dbo.tblSodooreSanad.fldSanad
where dbo.tblPardakht.fldType='pardakht') 
if @MaxDate is null
	set @MaxDate=0
set @minDate=(select min(flddate) from tblSodooreSanad inner join dbo.tblPardakht on dbo.tblPardakht.fldShomareSanad=dbo.tblSodooreSanad.fldSanad
where dbo.tblPardakht.fldType='pardakht') 
if @minDate is null	
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDatePishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDatePishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDatePishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDatePishForoosh]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(flddate) from tblRizePishForoosh)
if @MaxDate is null
	set @MaxDate=0
set @minDate=(select min(flddate) from tblRizePishForoosh)
if @minDate is null	
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDateSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDateSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDateSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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) 

if @MaxDate is null
	set @MaxDate=0

if @minDate is null
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxDateAndMinDateSanadEnteghalVajh]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxDateAndMinDateSanadEnteghalVajh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxDateAndMinDateSanadEnteghalVajh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[MaxDateAndMinDateSanadEnteghalVajh]
	@MaxDate bigint output,
	@minDate bigint output
AS
BEGIN
	
	SET NOCOUNT ON;

set @MaxDate=(select max(Convert(dec,flddate)) from tblSodooreSanad where  fldType='enteghalevajh') 
set @minDate=(select min(Convert(dec,flddate)) from tblSodooreSanad where  fldType='enteghalevajh') 

if @MaxDate is null
	set @MaxDate=0

if @minDate is null
	set @minDate=0

Return @MaxDate
Return @minDate
END
GO

-- ===============================================
-- SP: [dbo].[MaxShomareAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxShomareAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxShomareAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[MaxShomareAmani]
@lngMaxShomareAmani bigint output
as

begin

            			SET NOCOUNT ON;
	declare @lngCount bigint
	set @lngCount=(Select Count(fldShomareAmani) from tblRizeForoosh)
	if @lngCount>0 
		begin
 			set @lngMaxShomareAmani =(Select Max(fldShomareAmani) from tblRizeForoosh)
		end
	else
		set @lngMaxShomareAmani =0
end
GO

-- ===============================================
-- SP: [dbo].[MaxShomareBargashtAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxShomareBargashtAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxShomareBargashtAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[MaxShomareBargashtAmani]
@lngMaxShomareAmani bigint output
as

begin

            			SET NOCOUNT ON;
	declare @lngCount bigint
	set @lngCount=(Select Count(fldShomareBargashtAmani) from tblRizeBargashtAzForoosh)
	if @lngCount>0 
		begin
 			set @lngMaxShomareAmani =(Select Max(fldShomareBargashtAmani) from tblRizeBargashtAzForoosh)
		end
	else
		set @lngMaxShomareAmani =0
end
GO

-- ===============================================
-- SP: [dbo].[MaxShomareDaryaft]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxShomareDaryaft', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxShomareDaryaft] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[MaxShomareEnteghal]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxShomareEnteghal', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxShomareEnteghal] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[MaxShomareFish]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxShomareFish', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxShomareFish] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[MaxShomarePardakht]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxShomarePardakht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxShomarePardakht] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[MaxShomarePas]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxShomarePas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxShomarePas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[MaxShomareSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxShomareSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxShomareSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[MaxShomareSanad_Mandeh_Mojodi_Ashkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxShomareSanad_Mandeh_Mojodi_Ashkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxShomareSanad_Mandeh_Mojodi_Ashkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[MaxShomareSanad_Mandeh_Mojodi_Ebteda]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxShomareSanad_Mandeh_Mojodi_Ebteda', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxShomareSanad_Mandeh_Mojodi_Ebteda] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[MaxShomareVosool]
-- ===============================================
IF OBJECT_ID(N'dbo.MaxShomareVosool', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MaxShomareVosool] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[MinMaxDateAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.MinMaxDateAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MinMaxDateAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[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 @MinDate=0
				set @MinDate=@tmp
			else if @tmp<@MinDate
				begin
					set @MinDate =@tmp
				end

		end

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

		end

	set @tmp = (Select Min(fldDate) from tblRizeBargashtAzForoosh)
	if @tmp is not null
		begin
			if @MinDate=0
				set @MinDate=@tmp
			else 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 @MaxDate=0
				set @MaxDate=@tmp
			else if @tmp>@MaxDate
				begin
					set @MaxDate =@tmp
				end

		end

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

		end

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

		end

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

		end

END
GO

-- ===============================================
-- SP: [dbo].[MoghayeratFactorBaSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.MoghayeratFactorBaSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MoghayeratFactorBaSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter procedure [dbo].[MoghayeratFactorBaSanad]
as
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
begin
	create table #tbl1(
		fldSanad bigint,
		fldMablagh decimal
	)

	create table #tbl2(
		fldSanad bigint,
		fldMablagh decimal,
		fldBestankar decimal,
		fldDate bigint,
		fldShomareFactor bigint
	)

	insert into #tbl1
		(fldSanad,fldMablagh)
		(Select fldShomareSanad,Sum(fldMablaghKhales)  from tblRizeForoosh group by fldShomareSanad)

--		Select fldSanad from tblSodooreSanad Where fldSanad not in (Select fldSanad from #tbl1 )
insert into #tbl2 (fldSanad,fldMablagh,fldBestankar,fldDate )
(Select #tbl1.fldSanad,#tbl1.fldMablagh,tblSodooreSanad.fldBestankar,fldDate from #tbl1,tblSodooreSanad Where #tbl1.fldSanad=tblSodooreSanad.fldSanad And convert(dec,#tbl1.fldMablagh)<>convert(dec,tblSodooreSanad.fldBestankar) and fldMoinKamel='71301' and  abs(fldMablagh-fldBestankar)>30000 )--and fldRadif=3)

update #tbl2 set fldShomareFactor=tblForoosh.fldShomareFactorForoosh  from tblforoosh WHere #tbl2.fldSanad=tblForoosh.fldShomareSanad
--Select fldShomareFactor from tblRizeForoosh Where fldShomareSanad=15888
Select * from #tbl2 

end
GO

-- ===============================================
-- SP: [dbo].[MohasebeTarikh1]
-- ===============================================
IF OBJECT_ID(N'dbo.MohasebeTarikh1', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MohasebeTarikh1] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[MohasebeTarikh1] 
	-- Add the parameters for the stored procedure here
	(@fldDatejari bigint,
	@typemodedate1 varchar(20),
	@mobile int

	)
AS
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END

BEGIN
	
SET NOCOUNT ON;
create table #TempTb1 
(
id int,
fldSharheTafzili  Nvarchar(200) collate Persian_100_CI_AS,
fldOstan  Nvarchar(50) collate Persian_100_CI_AS,
fldCity  Nvarchar(50) collate Persian_100_CI_AS,
TDate1 bigint,
fldshomare  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeMeli  Nvarchar(20) collate Persian_100_CI_AS,
fldCodePosti  Nvarchar(20) collate Persian_100_CI_AS,
fldAddress  Nvarchar(200) collate Persian_100_CI_AS,
TypeMode varchar(20)

)


if @typemodedate1='sal'
begin
delete from #TempTb1 where TypeMode<>@typemodedate1

insert into #TempTb1(id,fldSharheTafzili,fldOstan,fldCity,TDate1,fldCodeMeli,fldCodePosti,fldAddress,TypeMode)
 select distinct dbo.tblTafzili.fldCodeTafzili,fldSharheTafzili,fldOstan,fldCity, fldDate1,fldCodeMeli
 ,fldCodePosti,fldAddress,'sal' 
 from tblTafzili INNER JOIN
	tblDaftarcheTell on dbo.tblDaftarcheTell.fldCodeTafzili=dbo.tblTafzili.fldCodeTafzili 	
 where SUBSTRING(CONVERT(nvarchar, fldDate1), 5, 4)=
 SUBSTRING(CONVERT(nvarchar, @fldDatejari), 5, 4)


end
if @typemodedate1='mah'
begin
  delete from #TempTb1 where TypeMode<>@typemodedate1

insert into #TempTb1(id,fldSharheTafzili,fldOstan,fldCity,TDate1,fldCodeMeli,fldCodePosti,fldAddress,TypeMode)
 select distinct dbo.tblTafzili.fldCodeTafzili,fldSharheTafzili,fldOstan,fldCity, fldDate1,fldCodeMeli
 ,fldCodePosti,fldAddress,@typemodedate1 
 from tblTafzili INNER JOIN
	tblDaftarcheTell on dbo.tblDaftarcheTell.fldCodeTafzili=dbo.tblTafzili.fldCodeTafzili 	
 where SUBSTRING(CONVERT(nvarchar, fldDate1), 7, 2)=
 SUBSTRING(CONVERT(nvarchar, @fldDatejari), 7, 2)


end

if @mobile=1 
		begin
declare @EmpCodeTafzili nvarchar(10)
			declare EmpCursor Cursor For
				Select id from #TempTb1  With (NoLock) 
					open EmpCursor
					fetch Next From EmpCursor into @EmpCodeTafzili
					While @@Fetch_Status = 0
						Begin	
															
							update #TempTb1  set  fldshomare=(Select top(1)  fldShomare from tblDaftarcheTell Where fldCodetafzili=@EmpCodeTafzili)
									where id=@EmpCodeTafzili
							Fetch Next from EmpCursor
						into @EmpCodeTafzili
					end

			Close EmpCurSor
			Deallocate EmpCursor
			end
 select id,fldSharheTafzili,fldOstan,fldCity,
 SUBSTRING(CONVERT(nvarchar, TDate1), 1, 4)+'/'+ SUBSTRING(CONVERT(nvarchar, TDate1), 5, 2)+'/'+ SUBSTRING(CONVERT(nvarchar, TDate1), 7, 2)as Tdate1
 ,fldshomare,fldCodeMeli,fldCodePosti,fldAddress from #TempTb1



END
GO

-- ===============================================
-- SP: [dbo].[MohasebeTarikh2]
-- ===============================================
IF OBJECT_ID(N'dbo.MohasebeTarikh2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[MohasebeTarikh2] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[MohasebeTarikh2] 
	-- Add the parameters for the stored procedure here
	(@fldDatejari bigint,
	@typemodedate2 varchar(20),
	@mobile int
	)
AS
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END

BEGIN
	
SET NOCOUNT ON;

create table #TempTb2 
(
id int,
fldSharheTafzili  Nvarchar(200) collate Persian_100_CI_AS,
fldOstan  Nvarchar(50) collate Persian_100_CI_AS,
fldCity  Nvarchar(50) collate Persian_100_CI_AS,
TDate2 bigint,
fldshomare  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeMeli  Nvarchar(20) collate Persian_100_CI_AS,
fldCodePosti  Nvarchar(20) collate Persian_100_CI_AS,
fldAddress  Nvarchar(200) collate Persian_100_CI_AS,
TypeMode varchar(20)

)


if @typemodedate2='sal'
begin
delete from #TempTb2 where TypeMode<>@typemodedate2

insert into #TempTb2(id,fldSharheTafzili,fldOstan,fldCity,TDate2,fldCodeMeli,fldCodePosti,fldAddress,TypeMode)
 select distinct dbo.tblTafzili.fldCodeTafzili,fldSharheTafzili,fldOstan,fldCity, fldDate2,fldCodeMeli
 ,fldCodePosti,fldAddress,@typemodedate2 
 from tblTafzili
 where SUBSTRING(CONVERT(nvarchar, fldDate2), 5, 4)=
 SUBSTRING(CONVERT(nvarchar, @fldDatejari), 5, 4)

 
end
if @typemodedate2='mah'
begin
  delete from #TempTb2 where TypeMode<>@typemodedate2

insert into #TempTb2(id,fldSharheTafzili,fldOstan,fldCity,TDate2,fldCodeMeli,fldCodePosti,fldAddress,TypeMode)
 select distinct dbo.tblTafzili.fldCodeTafzili,fldSharheTafzili,fldOstan,fldCity,fldDate2,fldCodeMeli
 ,fldCodePosti,fldAddress,@typemodedate2 
 from tblTafzili
 where SUBSTRING(CONVERT(nvarchar, fldDate2), 7, 2)=
 SUBSTRING(CONVERT(nvarchar, @fldDatejari), 7, 2)



end

if @mobile=1 
		begin
declare @EmpCodeTafzili nvarchar(10)
			declare EmpCursor Cursor For
				Select id from #TempTb2  With (NoLock) 
					open EmpCursor
					fetch Next From EmpCursor into @EmpCodeTafzili
					While @@Fetch_Status = 0
						Begin	
					

									
							update #TempTb2  set  fldshomare=(Select top(1)  fldShomare from tblDaftarcheTell Where fldCodetafzili=@EmpCodeTafzili)
									where id=@EmpCodeTafzili
							Fetch Next from EmpCursor
						into @EmpCodeTafzili
					end

			Close EmpCurSor
			Deallocate EmpCursor
			end

 select distinct id,fldSharheTafzili,fldOstan,fldCity,
 SUBSTRING(CONVERT(nvarchar, TDate2), 1, 4)+'/'+ SUBSTRING(CONVERT(nvarchar, TDate2), 5, 2)+'/'+ SUBSTRING(CONVERT(nvarchar, TDate2), 7, 2)as Tdate2,
 fldshomare,fldCodeMeli,fldCodePosti,fldAddress from #TempTb2



END
GO

-- ===============================================
-- SP: [dbo].[NameHesab]
-- ===============================================
IF OBJECT_ID(N'dbo.NameHesab', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[NameHesab] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[NameHesab]
@CodeHesab nvarchar(10),
@SharheHesab nvarchar(50) Output

as
begin
	set @SharheHesab=(Select fldSharhehesab from tblKolMoin Where fldCodeHesab=@CodeHesab)
end
GO

-- ===============================================
-- SP: [dbo].[NameKolMoin]
-- ===============================================
IF OBJECT_ID(N'dbo.NameKolMoin', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[NameKolMoin] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[NameKolMoin]
	@MoinKamel nvarchar(10),
	@strName nvarchar(50) output
AS
BEGIN

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

END
GO

-- ===============================================
-- SP: [dbo].[NamePrinter]
-- ===============================================
IF OBJECT_ID(N'dbo.NamePrinter', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[NamePrinter] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[NerkhnameKala]
-- ===============================================
IF OBJECT_ID(N'dbo.NerkhnameKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[NerkhnameKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[NerkhnameKala] 
	@CodeGroupKala varchar(5000),
	@sort nvarchar(20),
	@Mosbat int

AS
BEGIN
declare @Sum decimal

create table #TempShowMojoodi(

			fldCodeKala bigint,
			fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
			fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
			fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
			SumVorood decimal(18, 0),
			SumKhorooj decimal(18, 0),
			SumMande decimal(18, 0),
			fldTedadDarKarton decimal(18, 0),
			fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,
			fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,
			fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,
			fldCodeGroup bigint,
			fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
			fldNogheSefaresh decimal(18, 0),
			fldKharid bigint,
			fldArzesheMojoodi bigint

			)

create Table #temp1
(
	fldCodeKala bigint,
	fldNamekala nvarchar(200) COLLATE Persian_100_CI_AS,
	fldCodeGroup bigint,
	fldNameGroup nvarchar(200) COLLATE Persian_100_CI_AS,
	fldFeeForoosh decimal(18,4),
	fldFee1 decimal(18,4),
	fldFee2 decimal(18,4),
	fldFee3 decimal(18,4),
	fldFee4 decimal(18,4),
	fldFee5 decimal(18,4),
	fldFee6 decimal(18,4),
	fldCodeSharh1 bigint,
	fldCodeSharh2 bigint,
	fldCodeSharh3 bigint,
	fldCodeSharh4 bigint,
	fldCodeSharh5 bigint,
	fldCodeSharh6 bigint,
	fldSharhFee1 nvarchar(200) COLLATE Persian_100_CI_AS,	
	fldSharhFee2 nvarchar(200) COLLATE Persian_100_CI_AS,
	fldSharhFee3 nvarchar(200) COLLATE Persian_100_CI_AS,
	fldSharhFee4 nvarchar(200) COLLATE Persian_100_CI_AS,
	fldSharhFee5 nvarchar(200) COLLATE Persian_100_CI_AS,
	fldSharhFee6 nvarchar(200) COLLATE Persian_100_CI_AS,
	fldGheimatMasrafkonande decimal(18,4),
	fldCodeVahed1       varchar(100) COLLATE Persian_100_CI_AS,
	fldCodeVahed2       varchar(100) COLLATE Persian_100_CI_AS, 
	fldNameVahed1       nvarchar(100) COLLATE Persian_100_CI_AS, 
	FldNameVahed2       nvarchar(100) COLLATE Persian_100_CI_AS,
	fldTedaddarkarton bigint
)

create Table #tempOrder
(
Row1 bigint,
fldCodeSharh bigint,
fldFee decimal(18,4),
fldCodeKala bigint,
)



if @Mosbat=1
	begin
		--declare @Sum decimal
		insert into #TempShowMojoodi
		exec [ShowListMojoodieAnbarAll] 0,@Sum,0,2
	end

insert into #temporder
	(Row1,fldCodeSharh,fldFee,fldCodeKala)			
(SELECT 
   ROW_NUMBER() OVER (partition by fldCodeKala order by fldCodeKala,fldCodeSharh)  RowNo,fldCodeSharh ,fldfee,fldCodeKala    
FROM 
   tblMultiFeeDynamic )



insert into #temp1
	(fldCodeKala,fldFee1,fldfee2,fldfee3,fldfee4,fldfee5,fldfee6,fldCodeSharh1,fldCodeSharh2,fldCodeSharh3,fldCodeSharh4,fldCodeSharh5,fldCodeSharh6)
   SELECT DISTINCT fldCodeKala
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=1) AS Fee1
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=2) AS Fee2
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=3) AS Fee3
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=4) AS Fee4
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=5) AS Fee5
,(SELECT fldFee FROM #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=6) AS Fee6
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=1) AS fldCodeSharh1
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=2) AS fldCodeSharh2
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=3) AS fldCodeSharh3
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=4) AS fldCodeSharh4
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=5) AS fldCodeSharh5
,(Select fldCodeSharh from #tempOrder s2 WHERE s2.fldCodeKala=s1.fldCodeKala AND s2.Row1=6) AS fldCodeSharh6
FROM #tempOrder s1

	--create table #TempListKala1(
	--fldNameKala         nvarchar(300) COLLATE Persian_100_CI_AS, 
	--fldCodeKala         bigint,
	--fldCodeVahed1       varchar(100) COLLATE Persian_100_CI_AS,
	--fldCodeVahed2       varchar(100) COLLATE Persian_100_CI_AS, 
	--fldNameVahed        nvarchar(100) COLLATE Persian_100_CI_AS, 
	--FldNameVahed2       nvarchar(100) COLLATE Persian_100_CI_AS,
	--fldCodeGroup        bigint,
	--fldGroupName        nvarchar(300) COLLATE Persian_100_CI_AS,
	--fldFeeForoosh1    decimal(18,4) , 
	--fldFeeForoosh2    decimal(18,4) , 
	--fldFeeForoosh3    decimal(18,4) , 
	--fldFeeForoosh4    decimal(18,4) , 
	--fldFeeForoosh5    decimal(18,4) , 
	--fldFeeForoosh6    decimal(18,4) , 
	--fldFeeForoosh7    decimal(18,4) , 
	--fldFeeForoosh8    decimal(18,4) )


	
	--insert into #TempListKala1(fldNameKala,fldCodeKala,fldCodeVahed1,fldCodeVahed2,fldNameVahed,FldNameVahed2,
	--						  fldCodeGroup,fldGroupName)
	--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
	--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


insert into #temp1
	(fldCodeKala)
	Select fldCodeKala from tblKala Where fldCodeKala Not in (Select fldCodeKala from #temp1)

	update #temp1 set fldCodeSharh1=(Select top(1)fldCodeSharh1 from #temp1 Where fldCodeSharh1 is Not NULL)
	update #temp1 set fldCodeSharh2=(Select top(1)fldCodeSharh2 from #temp1 Where fldCodeSharh2 is Not NULL)
	update #temp1 set fldCodeSharh3=(Select top(1)fldCodeSharh3 from #temp1 Where fldCodeSharh3 is Not NULL)
	update #temp1 set fldCodeSharh4=(Select top(1)fldCodeSharh4 from #temp1 Where fldCodeSharh4 is Not NULL)
	update #temp1 set fldCodeSharh5=(Select top(1)fldCodeSharh5 from #temp1 Where fldCodeSharh5 is Not NULL)
	update #temp1 set fldCodeSharh6=(Select top(1)fldCodeSharh6 from #temp1 Where fldCodeSharh6 is Not NULL)


	update #temp1 set fldFeeForoosh =tblKala.fldFeeForoosh, fldGheimatMasrafkonande =tblKala.fldGhymatMasrafkonande,fldNamekala=tblkala.fldNameKala,fldCodeGroup=tblKala.fldCodeGroup,fldCodeVahed1=tblKala.fldCodeVahed1,fldCodeVahed2=tblkala.fldCodeVahed2 from tblkala Where tblkala.fldCodekala=#temp1.fldCodeKala


	if @CodeGroupKala<>''
	begin
		declare @StrDeleteGroupKala varchar(5000)
		set  @StrDeleteGroupKala='delete from #temp1
			where '+ @CodeGroupKala + ''
			execute(@StrDeleteGroupKala)
	end


	update #temp1 set fldNameGroup=tblGroupKala.fldGroupName from tblGroupKala Where #temp1.fldCodeGroup=tblGroupKala.fldGroupId
	update #temp1 set fldNamevahed1=tblVahed.fldNameVahed from tblVahed Where fldCodeVahed1=tblVahed.ID
	update #temp1 set fldNamevahed2=tblVahed.fldNameVahed from tblVahed Where fldCodeVahed2=tblVahed.id

	update #temp1 set fldSharhFee1=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh1=tblSharheFeeDynamic.fldCodeSharh
	update #temp1 set fldSharhFee2=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh2=tblSharheFeeDynamic.fldCodeSharh
	update #temp1 set fldSharhFee3=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh3=tblSharheFeeDynamic.fldCodeSharh
	update #temp1 set fldSharhFee4=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh4=tblSharheFeeDynamic.fldCodeSharh
	update #temp1 set fldSharhFee5=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh5=tblSharheFeeDynamic.fldCodeSharh
	update #temp1 set fldSharhFee6=tblSharheFeeDynamic.fldSharh from tblSharheFeeDynamic Where fldCodeSharh6=tblSharheFeeDynamic.fldCodeSharh
	update #temp1 set fldTedaddarkarton =tblKala.fldTedadJoz from tblKala where #temp1.fldCodeKala=tblKala.fldCodeKala
	update #temp1 set FldNameVahed2 ='' where fldCodeVahed2=1

	if @Mosbat=1
		delete from #temp1 Where fldCodeKala not in (Select fldcodeKala from #TempShowMojoodi)
	

	if @sort='codekala'
		select 
		fldNameKala,       
		fldCodeKala,       
		fldCodeVahed1,      
		fldCodeVahed2,      
		fldNameVahed1,       
		FldNameVahed2,      
		fldCodeGroup,      
		fldNameGroup, 
		fldFeeForoosh,      
		fldFee1,      
		fldFee2,      
		fldFee3,      
		fldFee4,      
		fldFee5,      
		fldFee6,      
		fldGheimatMasrafkonande,
		fldSharhFee1,
		fldSharhFee2,
		fldSharhFee3,
		fldSharhFee4,
		fldSharhFee5,
		fldSharhFee6,
		fldTedaddarkarton
		from #temp1
		ORDER BY fldCodeKala Asc
	else if @sort='namekala'
			select 
		fldNameKala,       
		fldCodeKala,       
		fldCodeVahed1,      
		fldCodeVahed2,      
		fldNameVahed1,       
		FldNameVahed2,      
		fldCodeGroup,      
		fldNameGroup,  
		fldFeeForoosh,     
		fldFee1,      
		fldFee2,      
		fldFee3,      
		fldFee4,      
		fldFee5,      
		fldFee6,      
		fldGheimatMasrafkonande,
		fldSharhFee1,
		fldSharhFee2,
		fldSharhFee3,
		fldSharhFee4,
		fldSharhFee5,
		fldSharhFee6,
		fldTedaddarkarton
		from #temp1
		ORDER BY fldNameKala Asc
	else if @sort='codegroup'
		select 
		fldNameKala,       
		fldCodeKala,       
		fldCodeVahed1,      
		fldCodeVahed2,      
		fldNameVahed1,       
		FldNameVahed2,      
		fldCodeGroup,      
		fldNameGroup,  
		fldFeeForoosh,     
		fldFee1,      
		fldFee2,      
		fldFee3,      
		fldFee4,      
		fldFee5,      
		fldFee6,      
		fldGheimatMasrafkonande,
		fldSharhFee1,
		fldSharhFee2,
		fldSharhFee3,
		fldSharhFee4,
		fldSharhFee5,
		fldSharhFee6,
		fldTedaddarkarton
		from #temp1
		ORDER BY fldCodeGroup Asc	


END
GO

-- ===============================================
-- SP: [dbo].[NextOrBeforFactorShakhs]
-- ===============================================
IF OBJECT_ID(N'dbo.NextOrBeforFactorShakhs', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[NextOrBeforFactorShakhs] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[NoeSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.NoeSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[NoeSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[NoeSanad]

@Sanad nvarchar(10),
@result nvarchar(50) output
as 

begin
	declare @Number bigint

	
	set @Number=(select fldShomareDaryaft as cnt from tbldaryaft where fldShomareSanad=@Sanad)
	if isnumeric(@number)=1 
		begin
			set @result ='شماره دریافت ' + CONVERT(varchar, @Number)
			return -1
		end

	set @Number=(select fldShomarePardakht as cnt from tblPardakht where fldShomareSanad=@Sanad)
	if isnumeric(@number)=1 
		begin
			set @result ='شماره پرداخت ' + CONVERT(varchar, @Number)
			return -1
		end

	set @Number=(select fldShomareFactorForoosh as cnt from tblForoosh where fldShomareSanad=@Sanad)
	if isnumeric(@number)=1 
		begin
			set @result ='شماره فروش  ' + CONVERT(varchar, @Number)
			return -1
		end
	set @Number=(select fldShomareFactorForoosh as cnt from tblBargashtAzForoosh where fldShomareSanad=@Sanad)
	if isnumeric(@number)=1 
		begin
			set @result ='شماره برگشت از فروش  ' + CONVERT(varchar, @Number)
			return -1
		end

	set @Number=(select fldShomareFactorKharid as cnt from tblKharid where fldShomareSanad=@Sanad)
	if isnumeric(@number)=1 
		begin
			set @result ='شماره خرید  ' + CONVERT(varchar, @Number)
			return -1
		end

	set @Number=(select fldShomareFactorKharid as cnt from tblBargashtAzKharid where fldShomareSanad=@Sanad)
	if isnumeric(@number)=1 
		begin
			set @result ='شماره برگشت از خرید  ' + CONVERT(varchar, @Number)
			return -1
		end

	set @Number=(select fldShomarePas as cnt from tblPas where fldShomareSanad=@Sanad)
	if isnumeric(@number)=1 
		begin
			set @result ='شماره پاس چک  ' + CONVERT(varchar, @Number)
			return -1
		end
	
	
	set @Number=(select fldShomareVosool as cnt from tblVosool where fldShomareSanad=@Sanad)
	if isnumeric(@number)=1 
		begin
			set @result ='شماره وصول چک  ' + CONVERT(varchar, @Number)
			return -1
		end
	
	
  set @Number= (select count(fldSanad) as cnt from tblSodooreSanad where fldSanad=@Sanad and fldtype='EbtedaAshkhas')
  if @Number>0 
	begin
		set @result ='مانده ابتدای دوره اشخاص '
		return -1
	end

set @Number= (select count(fldSanad) as cnt from tblSodooreSanad where fldSanad=@Sanad and fldtype='mojoodieebteda')
  if @Number>0 
	begin
		set @result ='مانده ابتدای دوره کالا '
		return -1
	end
	
set @Number= (select count(fldSanad) as cnt from tblSodooreSanad where fldSanad=@Sanad and fldtype='vam')
  if @Number>0 
	begin
		set @result ='سند کارمزد وام '
		return -1
	end

set @Number= (select count(fldSanad) as cnt from tblSodooreSanad where fldSanad=@Sanad and fldtype='mandebank')
  if @Number>0 
	begin
		set @result ='مانده ابتدای دوره بانک '
		return -1
	end

set @Number= (select count(fldSanad) as cnt from tblSodooreSanad where fldSanad=@Sanad and fldtype='checkebteda')
  if @Number>0 
	begin
		set @result ='چکهای دریافتی ابتدای دوره'
		return -1
	end

set @Number= (select count(fldSanad) as cnt from tblSodooreSanad where fldSanad=@Sanad and fldtype='checkebtedaPardakhti')
  if @Number>0 
	begin
		set @result ='چکهای پرداختی ابتدای دوره'
		return -1
	end

set @Number= (select count(fldSanad) as cnt from tblSodooreSanad where fldSanad=@Sanad and fldtype='BargashteCheckeVagoz')
  if @Number>0 
	begin
		set @result ='بازپسگیری چک فروخته شده'
		return -1
	end

set @Number= (select count(fldSanad) as cnt from tblSodooreSanad where fldSanad=@Sanad and fldtype='OdateCheck')
  if @Number>0 
	begin
		set @result ='عودت چک فروخته شده'
		return -1
	end

set @Number= (select count(fldSanad) as cnt from tblSodooreSanad where fldSanad=@Sanad and fldtype='bazpascheckekhodeman')
  if @Number>0 
	begin
		set @result ='بازپسگیری چک پرداختی'
		return -1
	end

	--select *  from tblSodooreSanad where fldSanad=44


end
GO

-- ===============================================
-- SP: [dbo].[OnlineUpdateTblhavale-Fast2]
-- ===============================================
IF OBJECT_ID(N'dbo.OnlineUpdateTblhavale-Fast2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[OnlineUpdateTblhavale-Fast2] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[OnlineUpdateTblhavale-Fast2]
	@dtTblHavale [dtHavaleGroup2]  readonly,
	@NoeKhata nvarchar(20) output
AS


BEGIN
	begin transaction transact
	begin try
		

	--delete zomorodo_majidmarashi.tblHavaleGroohi Where fldShomareHavale in (Select fldShomareHavale from @dtTblHavale)

	--select * from  tblHavaleGoroohi where fldVaziat is NULL or fldVaziat<>1 [zomorodo_majidmarashi].[tblHavaleGroohi]
	--select * from  tblTempHavaleGroohi where fldVaziat is NULL or fldVaziat<>1

				update tblHavaleGoroohi set tblHavaleGoroohi.fldVaziat=1,tblHavaleGoroohi.fldDateTahvil=tbl1.fldDateTahvil,tblHavaleGoroohi.fldTimeTahvil=tbl1.fldTimeTahvil 
FROM    (select * from  @dtTblHavale) as tbl1	
 INNER JOIN tblHavaleGoroohi 		
		on tblHavaleGoroohi.fldShomareFactor=tbl1.fldShomareFactor
		where 
		tblHavaleGoroohi.fldVaziat is NULL or tblHavaleGoroohi.fldVaziat=0


--			update tblHavaleGoroohi set tblHavaleGoroohi.fldVaziat=1,fldDateTahvil=tbl1.fldDateTahvil 
--FROM    (select fldCodeTafzili, fldShomareFactor, fldShomareHavale,fldDate,fldCodeRanande,fldDateUpdate,fldVaziat,fldCodeVizitor,fldLat,fldLon,fldDateTahvil,fldTimeTahvil from  @dtTblHavale) as tbl1	
-- INNER JOIN tblHavaleGoroohi 		
--		on tblHavaleGoroohi.fldShomareFactor=tbl1.fldShomareFactor
--		where 
--		tblHavaleGoroohi.fldVaziat is NULL or tblHavaleGoroohi.fldVaziat=0


	--INSERT        INTO             [zomorodo_majidmarashi].[tblHavaleGroohi]( fldCodeTafzili, fldShomareFactor,fldShomareHavale,fldDate, fldCodeRanande,fldDateUpdate,fldVaziat,fldcodeVizitor,fldLat,fldLon,fldDateTahvil,fldTimeTahvil)
																		



	commit transaction
			end try

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

		end catch
END
GO

-- ===============================================
-- SP: [dbo].[procGridBargashtAzForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.procGridBargashtAzForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[procGridBargashtAzForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

   update tblRizeBargashtAzForoosh set fldGhymatMasrafkonande=0 where fldGhymatMasrafkonande is null

   SELECT        dbo.tblRizeBargashtAzForoosh.fldRadif, dbo.tblRizeBargashtAzForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblRizeBargashtAzForoosh.fldSharhKala, dbo.tblRizeBargashtAzForoosh.fldTedadCarton, 
                         Convert(float,dbo.tblRizeBargashtAzForoosh.fldTedadJoz) as 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 fldGhymatMasrafkonandeKala,fldDateEngheza,fldbatchNumber,flddateSakht, tblRizeBargashtAzForoosh.fldGhymatMasrafkonande 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

-- ===============================================
-- SP: [dbo].[procGridBargashtAzKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.procGridBargashtAzKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[procGridBargashtAzKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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, 
                         convert(float, dbo.tblRizeBargashtAzKharid.fldTedadJoz)as 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,fldDateEngheza,fldBatchNumber,flddateSakht
			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

-- ===============================================
-- SP: [dbo].[procGridForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.procGridForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[procGridForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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, 
                         Convert(float,dbo.tblRizeForoosh.fldTedadJoz) as 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.fldDarsadArzeshAfzoode, 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,fldEshantion as fldType,fldDateEngheza,fldbatchnumber,fldDateSakht, tblRizeForoosh.fldGhymatMasrafkonande as fldGhymatMasrafkonandeForoosh,tblRizeForoosh.fldCodeMasterEshantion
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

-- ===============================================
-- SP: [dbo].[procGridForooshAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.procGridForooshAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[procGridForooshAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[procGridForooshAmani]
	@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, 
                         Convert(float,dbo.tblRizeForoosh.fldTedadJoz) as 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,fldDateEngheza
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.fldShomareAmani = @fldShomareFactor)
END
GO

-- ===============================================
-- SP: [dbo].[procGridForooshBargashtAmani]
-- ===============================================
IF OBJECT_ID(N'dbo.procGridForooshBargashtAmani', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[procGridForooshBargashtAmani] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[procGridForooshBargashtAmani]
	@fldShomareFactor bigint
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 #TBL1(
		fldRadif BIGINT,
		fldCodeKala bigint,
		fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
		fldSharhKala nvarchar(100) COLLATE Persian_100_CI_AS,
		fldTedadCarton nvarchar(10) COLLATE Persian_100_CI_AS,
		fldTedadJoz decimal(18,2),
		fldFeeJoz decimal(18,2),
		fldFeeYekCarton decimal(18,0),
		fldFeeKol decimal(18,0),
		fldDarsadTakhfif decimal(18,2),		
		fldMablaghTakhfif decimal(18,0),
		fldFeeVahed1BadAzTakhfif decimal(18,2),
		fldFeeVahed2BadAzTakhfif decimal(18,2),
		fldArzeshAfzode decimal(18,2),
		fldFeeKolBadAzTakhfif  decimal(18,0), 
        fldMablaghKhales  decimal(18,0), 
		fldCodeAnbar bigint, 
		fldNameVahed nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed2 nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameAnbar nvarchar(50) COLLATE Persian_100_CI_AS,
		fldVahed1Code int,
		fldVahed2Code int, 
		fldGhymatMasrafkonande decimal(18,0), 
		fldDateEngheza bigint
	)


   insert into #TBL1
		(fldRadif ,fldCodeKala,fldNameKala,fldSharhKala,fldTedadCarton,fldTedadJoz,fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif, 
			fldMablaghKhales,fldCodeAnbar,fldNameVahed,fldNameVahed2,fldNameAnbar,fldVahed1Code,fldVahed2Code,fldGhymatMasrafkonande,fldDateEngheza)
   SELECT        dbo.tblRizeBargashtAzForoosh.fldRadif, dbo.tblRizeBargashtAzForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblRizeBargashtAzForoosh.fldSharhKala, dbo.tblRizeBargashtAzForoosh.fldTedadCarton, 
                         Convert(float,dbo.tblRizeBargashtAzForoosh.fldTedadJoz) as 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,fldDateEngheza
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.fldShomareBargashtAmani = @fldShomareFactor)

update #tbl1 set fldCodeAnbar=tblRizeKharid.fldCodeAnbar from tblRizeKharid Where tblRizeKharid.fldShomareBargashtAmani=@fldShomareFactor
update #tbl1 set fldNameAnbar=tblAnbar.fldNameAnbar from tblAnbar Where fldCodeAnbar=tblAnbar.fldCode

Select fldRadif,fldCodeKala ,fldNameKala,fldSharhKala,fldTedadCarton,fldTedadJoz,fldFeeJoz,fldFeeYekCarton,fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,
		fldFeeKolBadAzTakhfif,fldMablaghKhales,fldCodeAnbar,fldNameVahed,fldNameVahed2,fldNameAnbar,fldVahed1Code,fldVahed2Code,fldGhymatMasrafkonande,fldDateEngheza  from #TBL1 
END
GO

-- ===============================================
-- SP: [dbo].[procGridHavaleHazine]
-- ===============================================
IF OBJECT_ID(N'dbo.procGridHavaleHazine', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[procGridHavaleHazine] AS BEGIN SET NOCOUNT ON; END')
END
GO

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

   SELECT     dbo.tblRizHavaleHazine.fldShomareSanad, dbo.tblRizHavaleHazine.fldRadif, dbo.tblRizHavaleHazine.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblRizHavaleHazine.fldSharhKala, dbo.tblRizHavaleHazine.fldTedadCarton, 
                         Convert(float,dbo.tblRizHavaleHazine.fldTedadJoz) as fldTedadJoz, dbo.tblRizHavaleHazine.fldFeeJoz, dbo.tblRizHavaleHazine.fldFeeYekCarton, dbo.tblRizHavaleHazine.fldFeeKol, 
                         dbo.tblRizHavaleHazine.fldDarsadTakhfif, dbo.tblRizHavaleHazine.fldMablaghTakhfif, dbo.tblRizHavaleHazine.fldFeeVahed1BadAzTakhfif, 
                         dbo.tblRizHavaleHazine.fldFeeVahed2BadAzTakhfif, dbo.tblRizHavaleHazine.fldArzeshAfzode,dbo.tblRizHavaleHazine.fldDarsadArzeshAfzoode, dbo.tblRizHavaleHazine.fldFeeKolBadAzTakhfif, 
                         dbo.tblRizHavaleHazine.fldMablaghKhales, dbo.tblRizHavaleHazine.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,fldEshantion as fldType,fldDateEngheza,tblRizHavaleHazine.fldGhymatMasrafkonande as fldGhymatMasrafkonandeForoosh,tblRizHavaleHazine.fldCodeMasterEshantion
FROM            dbo.tblAnbar INNER JOIN
                         dbo.tblRizHavaleHazine ON dbo.tblAnbar.fldCode = dbo.tblRizHavaleHazine.fldCodeAnbar INNER JOIN
                         dbo.tblKala ON dbo.tblRizHavaleHazine.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.tblRizHavaleHazine.fldShomareFactor = @fldShomareFactor)
END
GO

-- ===============================================
-- SP: [dbo].[procGridKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.procGridKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[procGridKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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, 
                         convert(float, dbo.tblRizeKharid.fldTedadJoz) as 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.tblRizeKharid.fldGhymatMasrafkonande,0) as fldGhymatMasrafkonande,fldDateEngheza,fldBatchNumber,fldDateSakht
			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

-- ===============================================
-- SP: [dbo].[procGridPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.procGridPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[procGridPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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, 
                         Convert(float,dbo.tblRizePishForoosh.fldTedadJoz) as 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,fldDarsadArzeshAfzoode, 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,fldEshantion as fldType
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

-- ===============================================
-- SP: [dbo].[procGridPishPishForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.procGridPishPishForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[procGridPishPishForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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, 
                         convert(float,dbo.tblRizePishPishForoosh.fldTedadJoz) as 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,dbo.tblRizePishPishForoosh.fldtype, 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,tblRizePishPishForoosh.fldCodeMasterEshantion
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

-- ===============================================
-- SP: [dbo].[QueryDynamic]
-- ===============================================
IF OBJECT_ID(N'dbo.QueryDynamic', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[QueryDynamic] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[QueryDynamic]
	@strQuery nvarchar(3000)
as
begin
	--declare	@strQuery nvarchar(3000)
	--set @strQuery='select * from tblForoosh'
	execute (@strQuery)
end
GO

-- ===============================================
-- SP: [dbo].[Report_ListAshkhas_groupby_CodeGroup_order_SharhTafsili_final]
-- ===============================================
IF OBJECT_ID(N'dbo.Report_ListAshkhas_groupby_CodeGroup_order_SharhTafsili_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Report_ListAshkhas_groupby_CodeGroup_order_SharhTafsili_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldShomare Nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeTafzili bigint, 
fldCodeMeli Nvarchar(50) COLLATE Persian_100_CI_AS,
fldAddress Nvarchar(400) COLLATE Persian_100_CI_AS

)
end
insert into #TempListAshkhas1(fldSharheTafzili,fldCodeGroup,fldGroupName,fldCodeTafzili,fldCodeMeli,fldAddress)
select dbo.tblTafzili.fldSharheTafzili,
dbo.tblTafzili.fldCodeGroup,
dbo.tblGroupAshkhas.fldGroupName,
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 


update #TempListAshkhas1 set fldShomare=tbl5.fldShomare from
(select fldShomare,fldcodetafzili from
	(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
	FROM            [tblDaftarcheTell]) DB_Address
	where RowNo=1) as tbl5 
	where #TempListAshkhas1.fldCodetafzili=tbl5.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

-- ===============================================
-- SP: [dbo].[Report_ListAshkhas_groupby_NameGroup_order_SharhTafsili_final]
-- ===============================================
IF OBJECT_ID(N'dbo.Report_ListAshkhas_groupby_NameGroup_order_SharhTafsili_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Report_ListAshkhas_groupby_NameGroup_order_SharhTafsili_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldShomare Nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeTafzili bigint, 
fldCodeMeli Nvarchar(50) COLLATE Persian_100_CI_AS,
fldAddress Nvarchar(400) COLLATE Persian_100_CI_AS

)
end
insert into #TempListAshkhas(fldSharheTafzili,fldCodeGroup,fldGroupName,fldCodeTafzili,fldCodeMeli,fldAddress)
select dbo.tblTafzili.fldSharheTafzili,
dbo.tblTafzili.fldCodeGroup,
dbo.tblGroupAshkhas.fldGroupName,
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




update #TempListAshkhas set fldShomare=tbl5.fldShomare from
(select fldShomare,fldcodetafzili from
	(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
	FROM            [tblDaftarcheTell]) DB_Address
	where RowNo=1) as tbl5 
	where #TempListAshkhas.fldCodetafzili=tbl5.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

-- ===============================================
-- SP: [dbo].[Report_ListKala_groupby_NameGroup_order_CodeKala_final]
-- ===============================================
IF OBJECT_ID(N'dbo.Report_ListKala_groupby_NameGroup_order_CodeKala_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Report_ListKala_groupby_NameGroup_order_CodeKala_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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) COLLATE Persian_100_CI_AS, 
fldCodeKala         bigint,
fldCodeVahed1       varchar(100) COLLATE Persian_100_CI_AS,
fldCodeVahed2       varchar(100) COLLATE Persian_100_CI_AS, 
fldNameVahed        nvarchar(100) COLLATE Persian_100_CI_AS, 
FldNameVahed2       nvarchar(100) COLLATE Persian_100_CI_AS,
fldCodeGroup        bigint,
fldGroupName        nvarchar(300) COLLATE Persian_100_CI_AS,
fldFeeForoosh       varchar(100) COLLATE Persian_100_CI_AS , 
fldFeeBadAzTakhfif  varchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh    varchar(50) COLLATE Persian_100_CI_AS,
fldNerkhePorsantKol varchar(50) COLLATE Persian_100_CI_AS,
fldNerkhePorsantJoz varchar(50) COLLATE Persian_100_CI_AS,
fldGhymatMasrafkonande varchar(50) COLLATE Persian_100_CI_AS,
fldSerial  varchar(50) COLLATE Persian_100_CI_AS)
end

insert into #TempListKala1(fldNameKala,fldCodeKala,fldCodeVahed1,fldCodeVahed2,fldNameVahed,FldNameVahed2,
                          fldCodeGroup,fldGroupName,fldFeeForoosh,fldFeeBadAzTakhfif,fldNogheSefaresh,
						  fldNerkhePorsantKol,fldNerkhePorsantJoz,fldGhymatMasrafkonande,fldSerial)
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,dbo.tblKala.fldGhymatMasrafkonande, dbo.tblKala.fldSerial
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,
fldGhymatMasrafkonande,
fldSerial
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

-- ===============================================
-- SP: [dbo].[Report_ListKala_groupby_NameGroup_order_NameKala_final]
-- ===============================================
IF OBJECT_ID(N'dbo.Report_ListKala_groupby_NameGroup_order_NameKala_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Report_ListKala_groupby_NameGroup_order_NameKala_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Report_ListKala_groupby_NameGroup_order_NameKala_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) COLLATE Persian_100_CI_AS, 
fldCodeKala         bigint,
fldCodeVahed1       varchar(100) COLLATE Persian_100_CI_AS,
fldCodeVahed2       varchar(100) COLLATE Persian_100_CI_AS, 
fldNameVahed        nvarchar(100) COLLATE Persian_100_CI_AS, 
FldNameVahed2       nvarchar(100) COLLATE Persian_100_CI_AS,
fldCodeGroup        bigint,
fldGroupName        nvarchar(300) COLLATE Persian_100_CI_AS,
fldFeeForoosh       varchar(100) COLLATE Persian_100_CI_AS , 
fldFeeBadAzTakhfif  varchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh    varchar(50) COLLATE Persian_100_CI_AS,
fldNerkhePorsantKol varchar(50) COLLATE Persian_100_CI_AS,
fldNerkhePorsantJoz varchar(50) COLLATE Persian_100_CI_AS,
fldGhymatMasrafkonande varchar(50) COLLATE Persian_100_CI_AS,
fldSerial  varchar(50) COLLATE Persian_100_CI_AS)
end

insert into #TempListKala1(fldNameKala,fldCodeKala,fldCodeVahed1,fldCodeVahed2,fldNameVahed,FldNameVahed2,
                          fldCodeGroup,fldGroupName,fldFeeForoosh,fldFeeBadAzTakhfif,fldNogheSefaresh,
						  fldNerkhePorsantKol,fldNerkhePorsantJoz,fldGhymatMasrafkonande,fldSerial)
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,dbo.tblKala.fldGhymatMasrafkonande, dbo.tblKala.fldSerial
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,
fldGhymatMasrafkonande,
fldSerial
from #TempListKala1
ORDER BY fldNameKala 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

-- ===============================================
-- SP: [dbo].[ReportAll_ListAshkhas_groupby_CodeGroup_order_SharhTafsili]
-- ===============================================
IF OBJECT_ID(N'dbo.ReportAll_ListAshkhas_groupby_CodeGroup_order_SharhTafsili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ReportAll_ListAshkhas_groupby_CodeGroup_order_SharhTafsili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ReportAll_ListAshkhas_groupby_CodeGroup_order_SharhTafsili]
as


create table #TempListAshkhas(
fldSharheTafzili Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldShomare Nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeTafzili bigint, 
fldCodeMeli Nvarchar(50) COLLATE Persian_100_CI_AS,
fldAddress Nvarchar(400) COLLATE Persian_100_CI_AS

)

insert into #TempListAshkhas (fldSharheTafzili ,fldCodeGroup ,fldGroupName ,fldCodeTafzili , fldCodeMeli ,fldAddress )
SELECT DISTINCT 
                         dbo.tblTafzili.fldSharheTafzili,dbo.tblTafzili.fldCodeGroup,dbo.tblGroupAshkhas.fldGroupName,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.tblTafzili.fldCodeTafzili, 
                         dbo.tblTafzili.fldSharheTafzili,dbo.tblTafzili.fldCodeMeli,dbo.tblTafzili.fldAddress

--ORDER BY  dbo.tblTafzili.fldSharheTafzili



update #TempListAshkhas set fldShomare=tbl5.fldShomare from
(select fldShomare,fldcodetafzili from
	(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
	FROM            [tblDaftarcheTell]) DB_Address
	where RowNo=1) as tbl5 
	where #TempListAshkhas.fldCodetafzili=tbl5.fldCodeTafzili

Select  fldSharheTafzili ,fldCodeGroup ,fldGroupName ,fldCodeTafzili ,fldShomare, fldCodeMeli ,fldAddress  from #TempListAshkhas ORDER BY  fldSharheTafzili
GO

-- ===============================================
-- SP: [dbo].[ReportAll_ListAshkhas_groupby_NameGroup_order_SharhTafsili]
-- ===============================================
IF OBJECT_ID(N'dbo.ReportAll_ListAshkhas_groupby_NameGroup_order_SharhTafsili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ReportAll_ListAshkhas_groupby_NameGroup_order_SharhTafsili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ReportAll_ListAshkhas_groupby_NameGroup_order_SharhTafsili]
as


create table #TempListAshkhas(
fldSharheTafzili Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldShomare Nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeTafzili bigint, 
fldCodeMeli Nvarchar(50) COLLATE Persian_100_CI_AS,
fldAddress Nvarchar(400) COLLATE Persian_100_CI_AS

)
insert into #TempListAshkhas (fldSharheTafzili ,fldCodeGroup ,fldGroupName ,fldCodeTafzili , fldCodeMeli ,fldAddress )
SELECT DISTINCT 
                         dbo.tblTafzili.fldSharheTafzili,dbo.tblTafzili.fldCodeGroup,dbo.tblGroupAshkhas.fldGroupName,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


update #TempListAshkhas set fldShomare=tbl5.fldShomare from
(select fldShomare,fldcodetafzili from
	(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
	FROM            [tblDaftarcheTell]) DB_Address
	where RowNo=1) as tbl5 
	where #TempListAshkhas.fldCodetafzili=tbl5.fldCodeTafzili

Select  fldSharheTafzili ,fldCodeGroup ,fldGroupName ,fldCodeTafzili ,fldShomare, fldCodeMeli ,fldAddress  from #TempListAshkhas ORDER BY  fldSharheTafzili
GO

-- ===============================================
-- SP: [dbo].[ReportAll_ListKala_groupby_NameGroup_order_CodeKala_final]
-- ===============================================
IF OBJECT_ID(N'dbo.ReportAll_ListKala_groupby_NameGroup_order_CodeKala_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ReportAll_ListKala_groupby_NameGroup_order_CodeKala_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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,dbo.tblKala.fldGhymatMasrafkonande,fldSerial
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,dbo.tblKala.fldGhymatMasrafkonande,fldSerial
						 
ORDER BY dbo.tblKala.fldCodeKala

end
GO

-- ===============================================
-- SP: [dbo].[ReportAll_ListKala_groupby_NameGroup_order_NameKala_final]
-- ===============================================
IF OBJECT_ID(N'dbo.ReportAll_ListKala_groupby_NameGroup_order_NameKala_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ReportAll_ListKala_groupby_NameGroup_order_NameKala_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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,dbo.tblKala.fldGhymatMasrafkonande,fldSerial
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,dbo.tblKala.fldGhymatMasrafkonande,fldSerial
						 
ORDER BY dbo.tblKala.fldNameKala

end
GO

-- ===============================================
-- SP: [dbo].[ReportBankSms]
-- ===============================================
IF OBJECT_ID(N'dbo.ReportBankSms', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ReportBankSms] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ReportBankSms]
	@CodeBank nvarchar(10),
	@noeVariz nvarchar(10), --واریز برداشت نامشخص همه
	@type nvarchar(10) -- جدید حذف شده همه
as
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
begin
	create table #tblTemp(
		[ID] [bigint]  NOT NULL,
	    [fldCodeBankAndroid] [nvarchar](10) NULL,
	    [fldCodeBankWindows] [nvarchar](10) COLLATE Persian_100_CI_AS NULL,
		[NameBank] [nvarchar](50) COLLATE Persian_100_CI_AS ,
	    [fldMatn] [nvarchar](Max) NULL,
        [fldVaziat] nvarchar(5),
		[fldVaziatShow] nvarchar(15),
        [fldVarizBardasht] nvarchar(10),
		[fldVarizBardashtmain] nvarchar(10),
        [fldMablagh] bigint,
        [fldTime] nvarchar(20),
        [fldShomarePeigiri] nvarchar(20),
        [fldMande] bigint,
        [fldForm] nvarchar(10),
        [fldShomareAmaliat] nvarchar(10),
		[fldCodeTafzili] nvarchar(20) COLLATE Persian_100_CI_AS,
		[fldNameShakhs] nvarchar(250) COLLATE Persian_100_CI_AS,
		[fldShomareCheck] nvarchar(30),
		[fldDateSms] nvarchar(10),
        [fldZaman] nvarchar(10),
		[fldSharh] nvarchar(200),
		[fldShomareHesab] nvarchar(30) COLLATE Persian_100_CI_AS
	)
	delete #tblTemp
	

	--update tblSmsFromServer set fldCodeBankWindows=tblKolMoin.fldCodeHesab from tblKolMoin Where tblKolMoin.fldInfo like + '%' + tblSmsFromServer.fldShomareHesab + '%' and fldCodeBankAndroid='1' --بغیر از بانک ملی
	--update tblSmsFromServer set fldCodeBankWindows=tblKolMoin.fldCodeHesab from tblKolMoin Where tblSmsFromServer.fldShomareHesab=tblKolMoin.fldInfo and fldCodeBankAndroid<>'1' --بغیر از بانک ملی
	
	if @CodeBank='allbank'
			insert into #tblTemp(ID, fldCodeBankAndroid, fldCodeBankWindows,NameBank, fldMatn, fldVaziat,fldVaziatShow, fldVarizBardasht,fldVarizBardashtmain, fldMablagh, fldTime, fldShomarePeigiri, fldMande, fldForm,fldShomareAmaliat,fldShomareCheck,fldDateSms,fldZaman,fldSharh,fldShomareHesab)
						SELECT        ID, fldCodeBankAndroid, fldCodeBankWindows,'' as NameBank,fldMatn, fldVaziat,
								 CASE WHEN fldVaziat = 'new' THEN 'جدید'    WHEN fldVaziat = 'end' THEN 'بسته'   END AS fldVaziatShow, 
								 CASE WHEN fldVarizBardasht = 'bardasht' THEN 'برداشت' WHEN fldVarizBardasht = 'variz' THEN 'واریز'  WHEN fldVarizBardasht = 'vosoolchk' THEN 'وصول چک' ELSE 'نامشخص' END AS fldVarizBardasht
								 ,fldVarizBardasht, fldMablagh, fldTime, 
								 fldShomarePeigiri, fldMande, fldForm,fldShomareAmaliat,fldShomareCheck,fldDateSms,fldZaman,fldSharh,fldShomareHesab
								FROM            tblSmsFromServer order by id desc
	else
			insert into #tblTemp(ID, fldCodeBankAndroid, fldCodeBankWindows,NameBank, fldMatn, fldVaziat,fldVaziatShow, fldVarizBardasht,fldVarizBardashtmain, fldMablagh, fldTime, fldShomarePeigiri, fldMande, fldForm,fldShomareAmaliat,fldShomareCheck,fldDateSms,fldZaman,fldSharh,fldShomareHesab)
						SELECT        ID, fldCodeBankAndroid, fldCodeBankWindows,'' as NameBank,fldMatn, fldVaziat,
								 CASE WHEN fldVaziat = 'new' THEN 'جدید'    WHEN fldVaziat = 'end' THEN 'بسته'  WHEN fldVaziat = 'delet' THEN 'حذف' END AS fldVaziatShow, 
								 CASE WHEN fldVarizBardasht = 'bardasht' THEN 'برداشت' WHEN fldVarizBardasht = 'variz' THEN 'واریز' ELSE 'نامشخص' END AS fldVarizBardasht
								 ,fldVarizBardasht, fldMablagh, fldTime, 
								 fldShomarePeigiri, fldMande, fldForm,fldShomareAmaliat,fldShomareCheck,fldDateSms,fldZaman,fldSharh,fldShomareHesab
								FROM            tblSmsFromServer  where fldCodeBankWindows=@CodeBank  order by id desc
	if @noeVariz='variz' --واریز
		delete #tblTemp where fldVarizBardashtmain<>N'variz' and fldVarizBardashtmain<>N'vosoolchk'
	else if @noeVariz='bardasht' --برداشت
		delete #tblTemp where fldVarizBardashtmain<>'bardasht'
	else if @noeVariz='unknown' --نامشخص
		delete #tblTemp where fldVarizBardashtmain<>'unknown'

				
	update #tblTemp set NameBank=tblKolMoin.fldSharheHesab from tblKolMoin Where tblKolMoin.fldInfo like + '%' + #tblTemp.fldShomareHesab + '%' and ( fldCodeBankAndroid='1' or fldCodeBankAndroid='3') --بغیر از بانک ملی و صادرات
	update #tblTemp set NameBank=tblKolMoin.fldSharheHesab from tblKolMoin Where #tblTemp.fldShomareHesab=tblKolMoin.fldInfo and fldCodeBankAndroid<>'1' and fldCodeBankAndroid<>'3' --بغیر از بانک ملی
	
	update #tblTemp set fldCodeTafzili=tblDaryaft.fldCodeTafzili from tblDaryaft Where #tblTemp.fldShomareAmaliat=tblDaryaft.fldShomareDaryaft  and fldForm='daryaft'
	update #tblTemp set fldCodeTafzili=tblPardakht.fldCodeTafzili from tblPardakht Where #tblTemp.fldShomareAmaliat=tblPardakht.fldShomarePardakht  and fldForm='pardakht'
	update #tblTemp set fldCodeTafzili=tblPardakht.fldCodeTafzili from tblPardakht Where #tblTemp.fldShomareAmaliat=tblPardakht.fldShomarePardakht  and fldForm='hazine'
	update #tblTemp set fldNameShakhs=tbltafzili.fldSharheTafzili from tbltafzili Where #tblTemp.fldCodeTafzili=tbltafzili.fldCodeTafzili
	update #tblTemp set fldForm='دریافت',fldVaziat='',fldVaziatShow='ثبت' where fldForm='daryaft' and fldVaziat<>'delet'
	update #tblTemp set fldForm='پرداخت',fldVaziat='',fldVaziatShow='ثبت' where fldForm='pardakht' and fldVaziat<>'delet'
	update #tblTemp set fldForm='هزینه',fldVaziat='',fldVaziatShow='ثبت' where fldForm='hazine' and fldVaziat<>'delet'
	update #tblTemp set fldForm='وصول چک',fldVaziat='',fldVaziatShow='ثبت' where fldForm='vosool' and fldVaziat<>'delet'
	update #tblTemp set fldForm='حذف',fldVaziat='delet',fldVaziatShow='حذف' where  fldVaziat='delet'
	
	
		if @type='new'
			delete #tblTemp where fldVaziat<>'new'
		if @type='notnew'
			delete #tblTemp where fldVaziat='new' or fldVaziat='delet'
		if @type='end'
			delete #tblTemp where fldVaziat<>'end'
		if @type='delet'
			delete #tblTemp where fldVaziat<>'delet'

		if @type<>'delet'
			delete #tblTemp where fldVaziat='delet'

	select  fldCodeBankAndroid,fldMatn,fldVarizBardasht,fldMablagh,fldMande,fldVaziat,fldVaziatShow,fldCodeBankWindows,NameBank,fldShomareHesab,fldTime,fldShomarePeigiri,fldForm,fldShomareAmaliat,fldNameShakhs,fldCodeTafzili,fldShomareCheck,fldDateSms,fldZaman,fldSharh,ID from #tblTemp
	
	


	
				--Case 
    --                when fldCodeBankAndroid='1' then 'ملی'
    --                when fldCodeBankAndroid='2' then 'ملت'
    --                when fldCodeBankAndroid='3' then 'صادرات'
    --                when fldCodeBankAndroid='4' then 'رسالت'                    
    --                when fldCodeBankAndroid='5' then 'شهر'  
    --             end
	end
GO

-- ===============================================
-- SP: [dbo].[ResetShomarefish]
-- ===============================================
IF OBJECT_ID(N'dbo.ResetShomarefish', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ResetShomarefish] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[RizeAmalkardeVarizeVizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.RizeAmalkardeVarizeVizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[RizeAmalkardeVarizeVizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[RizeAmalkardeVarizeVizitor]
@codeVasete nvarchar(15),
@datefrom nvarchar(15),
@dateuntil nvarchar(15)
as 

IF 1 = 0 BEGIN
 SET FMTONLY OFF
END

begin

	create table #tmp(
		fldCodeHesab nvarchar(20) COLLATE Persian_100_CI_AS,
		fldNameHesab nvarchar(250) COLLATE Persian_100_CI_AS,
		fldSharh nvarchar(250) COLLATE Persian_100_CI_AS,
		fldCodeTafzili nvarchar(250) COLLATE Persian_100_CI_AS,
		fldNameshakhs nvarchar(250) COLLATE Persian_100_CI_AS,
		fldBedehkar decimal(18,0),
		fldBestankar decimal(18,0),
		fldDate bigint,
		flddateShow nvarchar(20) COLLATE Persian_100_CI_AS,
		fldSanad bigint,
		fldShoamreAmaliat bigint,
		fldTypeAmaliat nvarchar(20)
	)

	delete #tmp
	declare @KolMoinForoosh nvarchar(10),@KolBank nvarchar(10),@kolsandoogh  nvarchar(10)



	execute CodeKolHesab 'bank',@kolbank output
	
	execute CodeKolHesab 'sandoogh' ,@kolsandoogh output


	insert into #tmp (fldCodeHesab,fldNameHesab,fldSharh,fldBedehkar,fldBestankar ,fldDate ,flddateShow,fldSanad )
		select fldMoinKamel,'',fldSharh,fldBedehkar,fldBestankar,fldDate,'',fldSanad from tblSodooreSanad Where fldVasete=@codeVasete and flddate between @datefrom and @dateuntil and (fldCodeKol=@kolbank or fldCodeKol=@kolsandoogh ) order by id 


  update #tmp set fldNameHesab=tblKolMoin.fldSharheHesab from tblKolMoin where #tmp.fldCodeHesab=tblKolMoin.fldCodeHesab

  update #tmp set fldDateshow=substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2)


  update #tmp SET fldTypeAmaliat='foroosh', fldSharh=fldSharh + '  فروش ' , fldShoamreAmaliat=tblForoosh.fldShomareFactorForoosh from tblForoosh where #tmp.fldSanad=tblForoosh.fldShomareSanad
  update #tmp SET fldTypeAmaliat='bargashtazforoosh', fldSharh=fldSharh + '  برگشت از فروش ' , fldShoamreAmaliat=tblBargashtAzForoosh.fldShomareFactorForoosh from tblBargashtAzForoosh where #tmp.fldSanad=tblBargashtAzForoosh.fldShomareSanad
  update #tmp SET fldTypeAmaliat='daryaft', fldSharh=fldSharh + '  دریافت ' , fldShoamreAmaliat=tblDaryaft.fldShomareDaryaft from tblDaryaft where #tmp.fldSanad=tblDaryaft.fldShomareSanad
  update #tmp SET fldTypeAmaliat='pardakht', fldSharh=fldSharh + '  پرداخت ' , fldShoamreAmaliat=tblPardakht.fldShomarePardakht from tblPardakht where #tmp.fldSanad=tblPardakht.fldShomareSanad
  update #tmp SET fldTypeAmaliat='vosool', fldSharh=fldSharh + '  وصول چک ' , fldShoamreAmaliat=tblCheckeDaryafti.fldSanadVosool from tblCheckeDaryafti where #tmp.fldSanad=tblCheckeDaryafti.fldSanadVosool

  update #tmp set fldCodeTafzili=tbl1.fldcodetafzili from  (Select distinct fldcodetafzili,fldSanad from tblSodooreSanad where isnumeric(fldcodetafzili)=1) as tbl1 where tbl1.fldSanad=#tmp.fldSanad
  update #tmp set fldnameshakhs=tbltafzili.fldSharheTafzili from tblTafzili where #tmp.fldCodeTafzili=tblTafzili.fldCodeTafzili

    select fldCodeHesab,fldNameHesab,fldSharh,fldcodetafzili,fldnameshakhs,fldShoamreAmaliat,fldSanad,fldBedehkar,fldBestankar,flddateShow,fldDate,fldTypeAmaliat  from #tmp




	--select * from tblSodooreSanad Where fldsanad=23
end
GO

-- ===============================================
-- SP: [dbo].[RizeFactorTasfieNashode]
-- ===============================================
IF OBJECT_ID(N'dbo.RizeFactorTasfieNashode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[RizeFactorTasfieNashode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[RizeFactorTasfieNashode]
	@ShomareFactor bigint

AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN
	
	CREATE TABLE #tmpRizeTasfie(	
	[Sharh][nvarchar](100) COLLATE Persian_100_CI_AS,
	[fldMablagheFactor] decimal(18,2),
	[ShomareDaryaft][bigint],	
	[fldMablagheMandeFactor]	[bigint],
	[fldTakhfif] decimal(18,2),
	[fldMablagheDaryaft][bigint],
	[fldMande][bigint]	,
	[fldDate] [bigint],
	[fldShomareBargashtAzForoosh] [bigint],
	[id] bigint
	)

	declare @Mablagh bigint
	
	delete #tmpRizeTasfie
	set @Mablagh=(Select fldMablagheFactor  from tblTasfie Where fldShomareFactor=@ShomareFactor)
	if @Mablagh is not null
		begin
			declare @DateFactor bigint
			set @DateFactor=(Select top(1) flddate from tblRizeForoosh Where fldShomareFactor=@ShomareFactor)
			
			update tblRizeTasfie set fldTakhfif=0 where fldTakhfif is null
			update tblRizeTasfie set fldMablagh=0 where fldMablagh is null

			insert into #tmpRizeTasfie
				(Sharh,ShomareDaryaft,fldMablagheFactor,fldTakhfif, fldMablagheMandeFactor,fldMablagheDaryaft,fldMande,fldDate,id)
				Select '',0, fldMablagheFactor ,fldTakhfif,fldMablagheMande,fldMablagheFactor-fldMablagheMande-fldTakhfif,fldMablagheMande , @DateFactor,1 from tblTasfie Where fldShomareFactor=@ShomareFactor
			--values('' , 0,1000000 ,0,1000000,right(@DateFactor,6),1)

			--select * from #tmpRizeTasfie
			--select * from tblrizetasfie

			--update #tmpRizeTasfie set fldtakhfif=(Select fldTakhfif  from tblTasfie Where fldShomareFactor=1)

			insert into #tmpRizeTasfie
				(Sharh,ShomareDaryaft, fldMablagheMandeFactor,fldtakhfif,fldMablagheDaryaft,fldMande,fldDate,fldShomareBargashtAzForoosh,id)
				(Select '',fldShomareDaryaft,0,fldtakhfif,fldMablagh-fldtakhfif,0,0,fldShomareBargashtAzForoosh,id from tblRizeTasfie Where fldShomareFactor=@ShomareFactor)
				
				
			---نمایش تاریخ دریافت
			update #tmpRizeTasfie set fldDate= tbl2.flddate from (SELECT DISTINCT tbl1.fldShomareSanad, tbl1.fldShomareFactor, tbl1.fldShomareDaryaft, tbl1.fldMablagh, tbl1.fldShomareBargashtAzForoosh, tblSodooreSanad.fldDate
				FROM         tblSodooreSanad INNER JOIN
                          (SELECT     tblRizeTasfie.ID, tblRizeTasfie.fldShomareFactor, tblRizeTasfie.fldShomareDaryaft, tblRizeTasfie.fldMablagh, 
                                                   tblRizeTasfie.fldShomareBargashtAzForoosh, tblDaryaft.fldShomareSanad
                             FROM         tblRizeTasfie INNER JOIN
                                                   tblDaryaft ON tblRizeTasfie.fldShomareDaryaft = tblDaryaft.fldShomareDaryaft) AS tbl1 ON tblSodooreSanad.fldSanad = tbl1.fldShomareSanad) as tbl2
				where #tmpRizeTasfie.ShomareDaryaft=tbl2.fldShomareDaryaft                                        
			 
		
		
		--update #tmpRizeTasfie set fldDate= tbl2.flddate from (SELECT DISTINCT tbl1.fldShomareSanad, tbl1.fldShomareFactor, tbl1.fldShomareDaryaft, tbl1.fldMablagh, tbl1.fldShomareBargashtAzForoosh, tblSodooreSanad.fldDate
		--		FROM         tblSodooreSanad INNER JOIN
  --                        (SELECT     tblRizeTasfie.ID, tblRizeTasfie.fldShomareFactor, tblRizeTasfie.fldShomareDaryaft, tblRizeTasfie.fldMablagh, 
  --                                                 tblRizeTasfie.fldShomareBargashtAzForoosh, tblDaryaft.fldShomareSanad
  --                           FROM         tblRizeTasfie INNER JOIN
  --                                                 tblDaryaft ON tblRizeTasfie.fldShomareDaryaft = tblDaryaft.fldShomareDaryaft) AS tbl1 ON tblSodooreSanad.fldSanad = tbl1.fldShomareSanad) as tbl2
		--		where #tmpRizeTasfie.ShomareDaryaft=tbl2.fldShomareDaryaft       
		--نمایش تاریخ برای برگشت از فروش	 
		update #tmpRizeTasfie set fldDate= tbl3.flddate from (SELECT DISTINCT tbl1.fldShomareSanad, tbl1.fldShomareFactor, tbl1.fldShomareDaryaft, tbl1.fldMablagh, tbl1.fldShomareBargashtAzForoosh, tblSodooreSanad.fldDate
			FROM         tblSodooreSanad INNER JOIN
                          (SELECT     tblRizeTasfie.ID, tblRizeTasfie.fldShomareFactor, tblRizeTasfie.fldShomareDaryaft, tblRizeTasfie.fldMablagh, 
                                                   tblRizeTasfie.fldShomareBargashtAzForoosh, tblBargashtAzForoosh.fldShomareSanad
                             FROM         tblRizeTasfie INNER JOIN
                                                   tblBargashtAzForoosh ON tblRizeTasfie.fldShomareBargashtAzForoosh = tblBargashtAzForoosh.fldShomareFactorForoosh) AS tbl1 ON 
                      tblSodooreSanad.fldSanad = tbl1.fldShomareSanad) as tbl3
				where #tmpRizeTasfie.fldShomareBargashtAzForoosh=tbl3.fldShomareBargashtAzForoosh      
		
		end
	Select Sharh,ShomareDaryaft,fldMablagheFactor,fldMablagheMandeFactor,fldTakhfif,fldMablagheDaryaft,fldMande,fldDate,fldShomareBargashtAzForoosh from #tmpRizeTasfie order by fldDate,id

END
GO

-- ===============================================
-- SP: [dbo].[Sanadetajmiei]
-- ===============================================
IF OBJECT_ID(N'dbo.Sanadetajmiei', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Sanadetajmiei] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Sanadetajmiei]
	@DarHad nvarchar(10),
	@Type nvarchar(5),
	@DateAz bigint,
	@dateTa bigint
 --@Filter nvarchar(10),
 --@dateAz bigint,
 --@dateta bigint
as 
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin

	create Table #tblTemp(	
	fldSanad bigint,
	fldCodeKol nvarchar(30) collate Persian_100_CI_AS,
	fldSharheKol nvarchar(250) collate Persian_100_CI_AS,
	fldCodeMoin nvarchar(30) collate Persian_100_CI_AS,
	fldSharheMoin nvarchar(250) collate Persian_100_CI_AS,
	fldMoinKamel nvarchar (30) collate Persian_100_CI_AS,
	fldCodeTafzili nvarchar(30) collate Persian_100_CI_AS,
	fldSharheTafzili nvarchar(25) collate Persian_100_CI_AS,
	fldCodeMarkaz1 nvarchar(30) collate Persian_100_CI_AS,
	fldSharheMarkaz1 nvarchar(250) collate Persian_100_CI_AS,
	fldCodeMarkaz2 nvarchar(30) collate Persian_100_CI_AS,
	fldSharheMarkaz2 nvarchar(250) collate Persian_100_CI_AS,
	fldSharh nvarchar(250) collate Persian_100_CI_AS,
	fldSharheKamel nvarchar(250) collate Persian_100_CI_AS,
	fldDate bigint,
	fldDateShow nvarchar(30) collate Persian_100_CI_AS, 
	fldDateFilter bigint,
	fldBedehkar bigint,
	fldBestankar bigint,
	fldBedBefor bigint,
	fldBesBefor bigint,
	fldMande bigint
	)
	--convert (varchar, fldShomareMoshtari) collate Persian_100_CI_AS
		DECLARE @NewLineChar AS CHAR(2) = CHAR(13) + CHAR(10)
		delete #tblTemp

	--if @DarHad='markaz2'
	--	insert into #tblTemp (fldCodeKol ,fldCodeMoin ,	fldMoinKamel ,	fldCodeTafzili ,fldCodeMarkaz1 ,fldCodeMarkaz2 ,fldDate ,fldDateShow,fldBedehkar,fldBestankar)
	--	Select fldCodeKol ,fldCodeMoin ,	fldMoinKamel ,	fldCodeTafzili ,fldCodeMarkaz1 ,fldCodeMarkaz2 ,fldDate ,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDateShow, Sum(fldBedehkar) as SumBed,Sum(fldBestankar) as SumBes from tblSodooreSanad	group by fldCodeKol ,fldCodeMoin ,	fldMoinKamel ,	fldCodeTafzili ,fldCodeMarkaz1 ,fldCodeMarkaz2 ,fldDate order by flddate
	--if @DarHad='markaz1'
	--	insert into #tblTemp (fldCodeKol ,fldCodeMoin ,	fldMoinKamel ,	fldCodeTafzili ,fldCodeMarkaz1 ,fldDate ,fldDateShow,fldBedehkar,fldBestankar)
	--	Select fldCodeKol ,fldCodeMoin ,	fldMoinKamel ,	fldCodeTafzili ,fldCodeMarkaz1 ,fldDate ,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDateShow, Sum(fldBedehkar) as SumBed,Sum(fldBestankar) as SumBes from tblSodooreSanad	group by fldCodeKol ,fldCodeMoin ,	fldMoinKamel ,	fldCodeTafzili ,fldCodeMarkaz1 ,fldDate order by flddate
	--if @DarHad='tafzili'
	--	insert into #tblTemp (fldCodeKol ,fldCodeMoin ,	fldMoinKamel ,	fldCodeTafzili ,fldDate ,fldDateShow,fldBedehkar,fldBestankar)
	--		Select fldCodeKol ,fldCodeMoin ,	fldMoinKamel ,	fldCodeTafzili ,fldDate ,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDateShow, Sum(fldBedehkar) as SumBed,Sum(fldBestankar) as SumBes from tblSodooreSanad	group by fldCodeKol ,fldCodeMoin ,	fldMoinKamel ,	fldCodeTafzili  ,fldDate order by flddate
	--if @DarHad='moin'			
	--	insert into #tblTemp (fldCodeKol ,fldCodeMoin,	fldMoinKamel ,fldDate ,fldDateShow,fldBedehkar,fldBestankar)
	--		Select fldCodeKol ,fldCodeMoin ,	fldMoinKamel,fldDate ,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDateShow, Sum(fldBedehkar) as SumBed,Sum(fldBestankar) as SumBes from tblSodooreSanad	group by fldCodeKol ,fldCodeMoin,	fldMoinKamel ,fldDate order by flddate
	--if @DarHad='kol'

	if @type='rooz'
		begin
			insert into #tblTemp (fldCodeKol ,fldDate ,fldDateShow,fldBedBefor,fldBesBefor)
				Select fldCodeKol ,fldDate ,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDateShow, Sum(fldBedehkar) as SumBed,Sum(fldBestankar) as SumBes from tblSodooreSanad Where flddate between @DateAz and @dateTa 	group by fldCodeKol ,fldDate having  Sum(fldBestankar) <>0 or Sum(fldBedehkar)<>0 order by flddate

				update #tblTemp set fldMande=fldBedBefor-fldBesBefor

				update #tblTemp set fldBedehkar=fldMande ,fldBestankar=0 where fldMande>0
				update #tblTemp set fldBedehkar=0, fldBestankar=-1*fldMande where fldMande<0

				update #tblTemp set fldBedehkar=0  where fldBedehkar is null
				update #tblTemp set fldBestankar=0  where fldBestankar is null
			
		end

			if @Type='mah'
				begin
					insert into #tblTemp (fldCodeKol ,fldDate ,fldDateShow,fldBedBefor,fldBesBefor)
							Select fldCodeKol , fldDate ,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + '01' as fldDateShow, Sum(fldBedehkar) as SumBed,Sum(fldBestankar) as SumBes from
							(Select fldCodeKol ,fldyear +fldmonth +  '01' as fldDate , fldBedehkar,fldBestankar from tblSodooreSanad ) as tbl1
							group by fldCodeKol ,fldDate order by flddate

					update #tblTemp set fldMande=fldBedBefor-fldBesBefor

					update #tblTemp set fldBedehkar=fldMande ,fldBestankar=0 where fldMande>0
					update #tblTemp set fldBedehkar=0, fldBestankar=-1*fldMande where fldMande<0

					update #tblTemp set fldBedehkar=0  where fldBedehkar is null
					update #tblTemp set fldBestankar=0  where fldBestankar is null
				end

			if @Type='tak'
				begin
					insert into #tblTemp (fldCodeKol ,fldBedBefor,fldBesBefor)
							Select fldCodeKol ,  Sum(fldBedehkar) as SumBed,Sum(fldBestankar) as SumBes from
							(Select fldCodeKol ,'0' as fldDate , fldBedehkar,fldBestankar from tblSodooreSanad where flddate between @DateAz and @dateTa ) as tbl1 
							group by fldCodeKol --,fldDate order by flddate

					update #tblTemp set fldMande=fldBedBefor-fldBesBefor

					update #tblTemp set fldBedehkar=fldMande ,fldBestankar=0 where fldMande>0
					update #tblTemp set fldBedehkar=0, fldBestankar=-1*fldMande where fldMande<0

					update #tblTemp set fldBedehkar=0  where fldBedehkar is null
					update #tblTemp set fldBestankar=0  where fldBestankar is null

					update #tblTemp set flddate=0 , flddateshow='0'
				end

	--if @Type='mah'
	--	begin
	--		insert into #tblTemp (fldCodeKol ,fldDate ,fldDateShow,fldBedBefor,fldBesBefor)
	--			Select fldCodeKol ,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + '01' as fldDateShow, Sum(fldBedehkar) as SumBed,Sum(fldBestankar) as SumBes from tblSodooreSanad	group by fldCodeKol ,fldyear,fldMonth order by fldyear,fldMonth
	--	end




			

	--update #tblTemp set fldSharh=tblKolMoin.fldSharheHesab from tblkolmoin where  tblkolmoin.fldCodeHesab =#tblTemp.fldCodeKol
	--update #tblTemp set fldSharh=#tblTemp.fldSharh + @NewLineChar  +tblKolMoin.fldSharheHesab from tblkolmoin where  tblkolmoin.fldCodeHesab =#tblTemp.fldMoinKamel and isnumeric(fldCodeMoin)=1
	--update #tblTemp set fldSharh=#tblTemp.fldSharh + @NewLineChar   + tblTafzili.fldSharheTafzili from tblTafzili where #tblTemp.fldCodeTafzili=tblTafzili.fldCodeTafzili and isnumeric(#tblTemp.fldCodeTafzili)=1
	--update #tblTemp set fldSharh=#tblTemp.fldSharh + @NewLineChar  + tblMarkaz1.fldSharh from tblMarkaz1 where #tblTemp.fldCodeMarkaz1=tblMarkaz1.fldCode and  isnumeric(#tblTemp.fldCodeMarkaz1)=1
	--update #tblTemp set fldSharh=#tblTemp.fldSharh + @NewLineChar  + tblMarkaz2.fldSharh from tblMarkaz2 where #tblTemp.fldCodeMarkaz2=tblMarkaz2.fldCode and  isnumeric(#tblTemp.fldCodeMarkaz2)=1

	select 	fldSanad ,fldCodeKol ,fldSharheKol,fldCodeMoin ,fldSharheMoin ,fldMoinKamel ,fldCodeTafzili ,fldSharheTafzili,fldCodeMarkaz1 ,fldSharheMarkaz1,fldCodeMarkaz2 ,fldSharheMarkaz2,fldSharh ,fldSharheKamel,fldDate ,fldDateShow , fldBedehkar ,fldBestankar from #tblTemp order by flddate,fldBestankar


end

--select SUM(fldbedehkar) as bed1,SUM(fldbestankar) as bes2,fldcodekol from tblSodooreSanad where fldDate=14030726 group by fldcodekol having   Sum(fldBestankar) <>0 or Sum(fldBedehkar)<>0
GO

-- ===============================================
-- SP: [dbo].[Serach_Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.Serach_Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Serach_Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[Serach_Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.Serach_Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Serach_Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Serach_Filter_Tbl_Tafsili_in_FormAshkhas_ByCodeTafzili_WithUserCode]
@codeTafzili nvarchar(10),
@userCode bigint
as
begin

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 

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 in (select code from @accessCodes) and
fldCodeTafzili=@codeTafzili 
end
GO

-- ===============================================
-- SP: [dbo].[SerachIntbl_GroupAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.SerachIntbl_GroupAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[SerachIntbl_GroupAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[SerachIntbl_GroupAshkhas]
@StrSearchTxt nvarchar(50)
as
select fldGroupId,fldGroupName from tblGroupAshkhas
where fldGroupName like '%' + @StrSearchTxt  + '%'
GO

-- ===============================================
-- SP: [dbo].[SerachIntbl_GroupAshkhas_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.SerachIntbl_GroupAshkhas_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[SerachIntbl_GroupAshkhas_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[SerachIntbl_GroupAshkhas_WithUserCode]
@StrSearchTxt nvarchar(50),
@userCode bigint
as
begin

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableGroupAshkhasCode(@userCode) 

select fldGroupId,fldGroupName from tblGroupAshkhas
where 
fldGroupId in (select code from @accessCodes) and
fldGroupName like '%' + @StrSearchTxt  + '%'


end
GO

-- ===============================================
-- SP: [dbo].[SerachIntbl_GroupKala]
-- ===============================================
IF OBJECT_ID(N'dbo.SerachIntbl_GroupKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[SerachIntbl_GroupKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[SerachIntbl_GroupKala]
@StrSearchTxt nvarchar(50)
as
select fldGroupId,fldGroupName  from tblGroupKala
where fldGroupName like '%' + @StrSearchTxt  + '%'
GO

-- ===============================================
-- SP: [dbo].[ShomareSanadDaryaftArchive]
-- ===============================================
IF OBJECT_ID(N'dbo.ShomareSanadDaryaftArchive', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShomareSanadDaryaftArchive] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShomareSanadDaryaftArchive]
@ShomareDaryaft bigint,
@ShomareSanad nvarchar(50) output

as

begin

	Set @ShomareSanad=(Select fldShomareSanad from tblDaryaft Where fldShomareDaryaft=@ShomareDaryaft)
end
GO

-- ===============================================
-- SP: [dbo].[ShomareSanadPardakhtArchive]
-- ===============================================
IF OBJECT_ID(N'dbo.ShomareSanadPardakhtArchive', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShomareSanadPardakhtArchive] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShomareSanadPardakhtArchive]
@ShomarePardakht bigint,
@ShomareSanad nvarchar(50) output

as

begin

	Set @ShomareSanad=(Select fldShomareSanad from tblPardakht Where fldShomarePardakht=@ShomarePardakht)
end
GO

-- ===============================================
-- SP: [dbo].[ShomareSanadVamArchive]
-- ===============================================
IF OBJECT_ID(N'dbo.ShomareSanadVamArchive', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShomareSanadVamArchive] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShomareSanadVamArchive]
@ShomareVam bigint,
@ShomareSanad nvarchar(50) output

as

begin

	Set @ShomareSanad=(Select fldShomareSanad from tblVamInfo Where fldShomareVam=@ShomareVam)
end
GO

-- ===============================================
-- SP: [dbo].[ShomareSanadVosoolArchive]
-- ===============================================
IF OBJECT_ID(N'dbo.ShomareSanadVosoolArchive', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShomareSanadVosoolArchive] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[Show_Mojoodie_Anbar]
-- ===============================================
IF OBJECT_ID(N'dbo.Show_Mojoodie_Anbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Show_Mojoodie_Anbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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) COLLATE Persian_100_CI_AS,
fldTedadeVorood decimal(18, 0),
fldTedadeKhorooj decimal(18, 0),
fldTedadeJoz decimal(18, 0), 
fldTedadeKol decimal(18, 0), 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS
)
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

-- ===============================================
-- SP: [dbo].[ShowAllAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowAllAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowAllAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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
											  where fldCodeNoe='1'
GO

-- ===============================================
-- SP: [dbo].[ShowAllAshkhas_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowAllAshkhas_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowAllAshkhas_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowAllAshkhas_WithUserCode]
@userCode bigint

as
begin

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 


	SELECT        tblTafzili.fldCodeTafzili, tblGroupAshkhas.fldGroupName, tblTafzili.fldCodeGroup, tblTafzili.fldSharheTafzili, tblTafzili.fldAddress
					FROM            tblTafzili INNER JOIN
											 tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
    where fldCodeTafzili in (select code from @accessCodes) and  fldCodeNoe='1' 

end
GO

-- ===============================================
-- SP: [dbo].[ShowAllAshkhas_WithUserCode2]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowAllAshkhas_WithUserCode2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowAllAshkhas_WithUserCode2] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowAllAshkhas_WithUserCode2]
@userCode bigint

as
begin

declare @cnt bigint

set @cnt=(select count(fldCodeGroup) as cnt from tblTafzili where fldCodeGroup='0' or fldCodeGroup is NULL)

if @cnt>0
	update tblTafzili set fldCodeGroup='100' where fldCodeGroup='0' or fldCodeGroup is NULL

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 


	SELECT        tblTafzili.fldCodeTafzili, tblGroupAshkhas.fldGroupName, tblTafzili.fldCodeGroup, tblTafzili.fldSharheTafzili, tblTafzili.fldAddress,tblTafzili.fldCodeNoe
					FROM            tblTafzili INNER JOIN
											 tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
    where fldCodeTafzili in (select code from @accessCodes) and  ( fldCodeNoe='1' or fldCodeNoe='0')

end
GO

-- ===============================================
-- SP: [dbo].[ShowAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[ShowAnbar]

as
begin
	select [fldCode],[fldNameAnbar],[fldCodeposti],[ID] from tblAnbar
		where fldCode<2000
		order by id
end
GO

-- ===============================================
-- SP: [dbo].[ShowArchiveCheckVagozari]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowArchiveCheckVagozari', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowArchiveCheckVagozari] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ShowAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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+'%' and  fldCodeNoe='1' 
			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 and  fldCodeNoe='1' 
			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	 and  fldCodeNoe='1' 										 
			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 and  fldCodeNoe='1' 
			end
GO

-- ===============================================
-- SP: [dbo].[ShowAshkhas_Filter_CodeKala]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowAshkhas_Filter_CodeKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowAshkhas_Filter_CodeKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowAshkhas_Filter_CodeKala_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowAshkhas_Filter_CodeKala_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowAshkhas_Filter_CodeKala_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowAshkhas_Filter_CodeKala_WithUserCode]
@CodeShakhs nvarchar(200),
@CodeGroup  bigint,
@userCode bigint
as
begin

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 

	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 in (select code from @accessCodes) and
											 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 in (select code from @accessCodes) and
											 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											 
											 where  fldCodeTafzili in (select code from @accessCodes)
			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 in (select code from @accessCodes) and
											 fldCodeGroup=@CodeGroup
			end

end
GO

-- ===============================================
-- SP: [dbo].[ShowAshkhas-WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowAshkhas-WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowAshkhas-WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowAshkhas-WithUserCode]
@NameShakhs nvarchar(200),
@CodeGroup  bigint,
@userCode bigint
as
begin

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 

	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 
											 fldCodeTafzili in (select code from @accessCodes) and
											 fldSharheTafzili like '%'+@NameShakhs+'%' and  fldCodeNoe='1' 
			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 in (select code from @accessCodes) and
											 fldSharheTafzili like '%'+@NameShakhs+'%' and fldCodeGroup=@CodeGroup and  fldCodeNoe='1' 
			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											 
											 where fldCodeTafzili in (select code from @accessCodes)  and  fldCodeNoe='1' 
			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 in (select code from @accessCodes) and
											 fldCodeGroup=@CodeGroup and  fldCodeNoe='1' 
			end


end
GO

-- ===============================================
-- SP: [dbo].[ShowBank]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowBank', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowBank] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[ShowBank]
@CodeKolHesab nvarChar(8)
as
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin
	
	create table #tblTemp (
		[fldCodeHesab] nvarchar(100) COLLATE Persian_100_CI_AS,
		[fldSharheHesab] nvarchar(max) COLLATE Persian_100_CI_AS,
		[ID] bigint,
		fldinfo nvarchar(100) COLLATE Persian_100_CI_AS,
		fldMande decimal(18,2),
		fldUnActive int
	
	)
	insert into #tblTemp (fldCodeHesab,[fldSharheHesab],[ID],fldinfo,fldUnActive )
		select [fldCodeHesab],[fldSharheHesab],[ID],fldinfo,fldUnActive from tblKolMoin
			Where fldCodeHesab<>@CodeKolHesab and left(fldCodeHesab,len(@CodeKolHesab))=@CodeKolHesab
			order by fldUnActive,fldCodeHesab

	--select * from #tblTemp

	update #tblTemp set fldMande= tbl1.fldBedehkar from 
		(select fldBedehkar,fldMoinKamel from tblSodooreSanad Where fldtype='mandebank') as tbl1
		where tbl1.fldMoinKamel=#tblTemp.fldCodeHesab

	update #tblTemp set fldMande=0 where fldMande Is NUll

	select 		[fldCodeHesab] ,[fldSharheHesab] ,[ID],fldinfo ,fldMande,fldUnActive  from #tblTemp order by fldUnActive,fldCodeHesab
end
GO

-- ===============================================
-- SP: [dbo].[ShowBankeMa]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowBankeMa', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowBankeMa] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[ShowBankeMa]

as
begin
		declare @strCodeKoleHesab nvarchar(10)
		execute CodeKolHesab 'bank',@strcodekolehesab output

	select [fldSharheHesab] as fldNameBank,[fldCodeHesab],fldInfo from tblKolMoin
		where  fldCodeHesab like @strCodeKoleHesab + '%' and len(fldCodeHesab)>len(@strCodeKoleHesab)
		order by fldCodeHesab
end
GO

-- ===============================================
-- SP: [dbo].[ShowBankeMa2]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowBankeMa2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowBankeMa2] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[ShowBankeMa2]

as
begin
		declare @strCodeKoleHesab nvarchar(10)
		execute CodeKolHesab 'bank',@strcodekolehesab output

	select [fldSharheHesab] as fldNameBank,[fldCodeHesab] as fldCodeBank from tblKolMoin
		where  fldCodeHesab like @strCodeKoleHesab + '%' and len(fldCodeHesab)>len(@strCodeKoleHesab)
		order by fldCodeHesab
end
GO

-- ===============================================
-- SP: [dbo].[ShowBankeMoshtari]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowBankeMoshtari', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowBankeMoshtari] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[ShowBankeMoshtari]

as
begin
	select [fldNameBank],[ID] from tblBankeMoshtari
		order by id
end
GO

-- ===============================================
-- SP: [dbo].[ShowBankInFormKhabandanCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowBankInFormKhabandanCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowBankInFormKhabandanCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowCheckDaryafti]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowCheckDaryafti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowCheckDaryafti] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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.fldsayad,tblCheckeDaryafti.fldShaba, 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,fldSharheDaryaft
		FROM            tblCheckeDaryafti INNER JOIN
									tblBankeMoshtari ON tblCheckeDaryafti.fldCodeBank = tblBankeMoshtari.ID
		WHERE        (tblCheckeDaryafti.fldSanad = @ShomareSanad)
	return
end
GO

-- ===============================================
-- SP: [dbo].[ShowCheckDaryaftiAndVagozariInFormVosoolCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowCheckDaryaftiAndVagozariInFormVosoolCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowCheckDaryaftiAndVagozariInFormVosoolCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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 or fldShomareEnteghal is Not Null) AND (dbo.tblCheckeDaryafti.fldVaziat IS NULL) OR
                         (dbo.tblCheckeDaryafti.fldShomarePardakht IS NULL) AND (dbo.tblCheckeDaryafti.fldVaziat = 'vagozari' or dbo.tblCheckeDaryafti.fldVaziat ='Bargasht' )  or  (dbo.tblCheckeDaryafti.fldVaziat ='forooshecheck' and isnumeric(dbo.tblCheckeDaryafti.fldShomareEnteghal)=1 and dbo.tblCheckeDaryafti.fldShomareOdat is  null)
			order by tblCheckeDaryafti.fldDateSarResid,tblCheckeDaryafti.fldDateDaryaft
END
GO

-- ===============================================
-- SP: [dbo].[ShowCheckDaryaftiAndVagozarNashodeAndVosoolNashodeINfrmKhabandan]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowCheckDaryaftiAndVagozarNashodeAndVosoolNashodeINfrmKhabandan', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowCheckDaryaftiAndVagozarNashodeAndVosoolNashodeINfrmKhabandan] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowCheckDaryaftiVosoolVaVagozarNashode]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowCheckDaryaftiVosoolVaVagozarNashode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowCheckDaryaftiVosoolVaVagozarNashode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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   ( fldvaziat is null or   fldvaziat = 'Bargasht') and   (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

-- ===============================================
-- SP: [dbo].[ShowCheckPardakhti]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowCheckPardakhti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowCheckPardakhti] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ShowCode_Daryaft_Daramad]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowCode_Daryaft_Daramad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowCode_Daryaft_Daramad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowDaryaftInfo]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowDaryaftInfo', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowDaryaftInfo] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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)
				set @CodeTafzili=(Select TOP (1) fldCodeTafzili from tblSodooreSanad Where fldSanad=@shomareSanad and isnumeric(fldCodeTafzili)=1 )
				if @CodeTafzili is null
					set @CodeTafzili=''
			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

-- ===============================================
-- SP: [dbo].[ShowDaryaftInfoChandBank]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowDaryaftInfoChandBank', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowDaryaftInfoChandBank] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowDaryaftInfoChandBank]
@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,

----بانک2
@Bank2 decimal output,
@CodeMoinBank2 nvarchar(10) output,
@SBank2 nvarchar(200) output,

----بانک3
@Bank3 decimal output,
@CodeMoinBank3 nvarchar(10) output,
@SBank3 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
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
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),@cntBank int
		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)
				set @CodeTafzili=(Select TOP (1) fldCodeTafzili from tblSodooreSanad Where fldSanad=@shomareSanad and isnumeric(fldCodeTafzili)=1 )
				if @CodeTafzili is null
					set @CodeTafzili=''
			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

		--بانک

CREATE TABLE #tmp(
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[fldCode] [nvarchar](20) NULL,
	[fldMablagh] [decimal](18, 0) NULL,
	[fldSharh] [nvarchar](150)
) ON [PRIMARY]

--delete #tmp


	--select * from #tmp
		execute CodeKolHesab  'bank', @KolBank output

		insert into #tmp (fldmablagh,fldCode,fldSharh)
			Select isnull(fldBedehkar,0),fldMoinKamel,isnull(fldSharh,'') from tblSodooreSanad where  fldCodeKol=@KolBank and fldSanad=@ShomareSanad 

		set @cntBank=(select count(id) from #tmp)

		set @strMablagh=(Select fldmablagh from #tmp where id=1)
		set @CodeMoinBank=(Select fldCode from #tmp where id=1)
		set @SBank=(Select fldSharh from #tmp where id=1)
		--set @strMablagh=(Select isnull(fldBedehkar,0) from tblSodooreSanad Where fldCodeKol=111 and fldSanad=35)
		--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

		--if @cntBank=2
		--	begin
				set @strMablagh=(Select fldmablagh from #tmp where id=2)
				set @CodeMoinBank2=(Select fldCode from #tmp where id=2)
				set @SBank2=(Select fldSharh from #tmp where id=2)
				if @strMablagh is null
					begin			
						set @bank2=0
						set @CodeMoinBank2=''
						set @SBank2=''
					end
				else
					begin			
						set @bank2=Convert(dec,@strMablagh)
				end
			--end

		--if @cntBank=3
		--	begin
				set @strMablagh=(Select fldmablagh from #tmp where id=3)
				set @CodeMoinBank3=(Select fldCode from #tmp where id=3)
				set @SBank3=(Select fldSharh from #tmp where id=3)
				if @strMablagh is null
					begin			
						set @bank3=0
						set @CodeMoinBank3=''
						set @SBank3=''
					end
				else
					begin			
						set @bank3=Convert(dec,@strMablagh)
				end
			--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


	--set @Bank3 =0
	--set @CodeMoinBank3 =''
	--set @SBank3 =''

	--set @Bank2 =0
	--set @CodeMoinBank2 =''
	--set @SBank2 =''

	--set @Bank =0
	--set @CodeMoinBank =''
	--set @SBank =''

		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

-- ===============================================
-- SP: [dbo].[ShowDastrasiSandoogh]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowDastrasiSandoogh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowDastrasiSandoogh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ShowDastrasiSandoogh] 
	@CodeUser bigint,
	@CodeSanadoogh bigint output,
	@CodeBank bigint  output,
	@ElzamiSandoogh nvarchar(10) output,
	@Elzamibank nvarchar(10) output
AS
BEGIN
	set @CodeSanadoogh=(Select fldSandoogh from tblDastrasiSandoogh
							where fldCodeUser=@CodeUser and fldType ='sandoogh')
	if @CodeSanadoogh is null
		set @CodeSanadoogh=1

	set @ElzamiSandoogh=(Select fldElzamiSandoogh from tblDastrasiSandoogh
							where fldCodeUser=@CodeUser and fldType ='sandoogh')
	if @ElzamiSandoogh is null
		set @ElzamiSandoogh='false'

	set @CodeBank=(Select fldSandoogh from tblDastrasiSandoogh
							where fldCodeUser=@CodeUser and fldType ='bank')
	if @CodeBank  is null
		set @CodeBank=1

	set @Elzamibank=(Select fldElzamiBank from tblDastrasiSandoogh
							where fldCodeUser=@CodeUser and fldType ='bank')
	if @Elzamibank is null
		set @Elzamibank='false'

END
GO

-- ===============================================
-- SP: [dbo].[ShowHesabKolMoin]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowHesabKolMoin', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowHesabKolMoin] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[ShowHesabKolMoin]
@CodeKolHesab nvarChar(8)
as
begin
	select [fldCodeHesab],[fldSharheHesab],[ID] from tblKolMoin
		Where fldCodeHesab<>@CodeKolHesab and left(fldCodeHesab,len(@CodeKolHesab))=@CodeKolHesab and fldUnActive=0
		order by fldCodeHesab
end
GO

-- ===============================================
-- SP: [dbo].[ShowHesabKolMoin_Filter]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowHesabKolMoin_Filter', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowHesabKolMoin_Filter] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ShowHesabKolMoinAllBedoneMarkaz]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowHesabKolMoinAllBedoneMarkaz', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowHesabKolMoinAllBedoneMarkaz] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[ShowHesabKolMoinAllBedoneMarkaz]

as
begin
	select [fldCodeHesab],[fldSharheHesab],[ID],[fldCodeNoeHesab] from tblKolMoin  where fldMarkazFirst<>N'فعال' and fldMarkazSecond<>N'فعال'--and fldCodeNoeHesab<>'2'
		order by fldCodeHesab
end


--select * from tblkolmoin where fldCodeHesab=61223
GO

-- ===============================================
-- SP: [dbo].[ShowHesabKolMoinNoeTafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowHesabKolMoinNoeTafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowHesabKolMoinNoeTafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ShowHesabKolMoinSandooghBank]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowHesabKolMoinSandooghBank', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowHesabKolMoinSandooghBank] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ShowHesabKolMoinWithType]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowHesabKolMoinWithType', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowHesabKolMoinWithType] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ShowInfo]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowInfo', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowInfo] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowInfoChecksKhabandehShodeInFormVagozri]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowInfoChecksKhabandehShodeInFormVagozri', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowInfoChecksKhabandehShodeInFormVagozri] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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') order by dbo.tblCheckeDaryafti.fldDateSarResid
END
GO

-- ===============================================
-- SP: [dbo].[ShowInfoEnteghal]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowInfoEnteghal', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowInfoEnteghal] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowList_ReportJaameBargashtAzFoRoosh_RizeForoosh_final]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowList_ReportJaameBargashtAzFoRoosh_RizeForoosh_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowList_ReportJaameBargashtAzFoRoosh_RizeForoosh_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ShowList_ReportJaameBargashtAzFoRoosh_RizeForoosh_final]
	@userCode bigint,
	@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..#TempRizeBargashtAzForoosh') IS NOT NULL
 begin
	delete from  #TempRizeBargashtAzForoosh
 end
else 
begin
create table #TempRizeBargashtAzForoosh(

fldShomareSanad Nvarchar(30) COLLATE Persian_100_CI_AS,
fldShomareFactor Nvarchar(30) COLLATE Persian_100_CI_AS,
fldCodeTafsili Nvarchar(30) COLLATE Persian_100_CI_AS,
fldSharheTafzili Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeAnbar Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeKala bigint,
fldNameKala Nvarchar(200) COLLATE Persian_100_CI_AS,
fldGhymatMasrafkonande Nvarchar(100) COLLATE Persian_100_CI_AS,
fldSharhKala Nvarchar(250) COLLATE Persian_100_CI_AS,
fldTedadCarton Nvarchar(100) COLLATE Persian_100_CI_AS, 
fldTedadJoz Nvarchar(100) COLLATE Persian_100_CI_AS,
fldFeeJoz Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldFeeYekCarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldFeeKol Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldDarsadTakhfif Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldMablaghTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldFeeVahed1BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS,
fldFeeVahed2BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldArzeshAfzode Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldFeeKolBadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldMablaghKhales Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldType Nvarchar(50) COLLATE Persian_100_CI_AS, 
fldDate int, 
fldGroupId Nvarchar(30) COLLATE Persian_100_CI_AS,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeVasete Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameVasete Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldGroupNameAshkhas Nvarchar(200) COLLATE Persian_100_CI_AS,
fldTedadJozKarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS
)
end

-- Get All AccessKala
declare @accessKala table(code bigint)

insert into @accessKala(code)
--exec ZSP_GetKalaAccesses @userCode
exec [ZSP_GetAccessableGroupKalaCode] @userCode

INSERT INTO #TempRizeBargashtAzForoosh(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.tblRizeBargashtAzForoosh.fldShomareSanad, dbo.tblRizeBargashtAzForoosh.fldShomareFactor, dbo.tblRizeBargashtAzForoosh.fldCodeTafsili, tblTafzili_1.fldSharheTafzili, 
                         dbo.tblRizeBargashtAzForoosh.fldCodeAnbar, dbo.tblAnbar.fldNameAnbar, dbo.tblRizeBargashtAzForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblKala.fldGhymatMasrafkonande, 
                         dbo.tblRizeBargashtAzForoosh.fldSharhKala, dbo.tblRizeBargashtAzForoosh.fldTedadCarton,ABS(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.fldType, dbo.tblRizeBargashtAzForoosh.fldDate, 
                         dbo.tblGroupKala.fldGroupId, dbo.tblGroupKala.fldGroupName, dbo.tblRizeBargashtAzForoosh.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.tblRizeBargashtAzForoosh INNER JOIN
                         dbo.tblAnbar ON dbo.tblRizeBargashtAzForoosh.fldCodeAnbar = dbo.tblAnbar.fldCode INNER JOIN
                         dbo.tblKala ON dbo.tblRizeBargashtAzForoosh.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.tblRizeBargashtAzForoosh.fldCodeTafsili = tblTafzili_1.fldCodeTafzili LEFT OUTER JOIN
                         dbo.tblTafzili ON dbo.tblRizeBargashtAzForoosh.fldCodeVasete = dbo.tblTafzili.fldCodeTafzili LEFT OUTER JOIN
                         dbo.tblGroupAshkhas AS tblGroupAshkhas_1 ON dbo.tblRizeBargashtAzForoosh.fldCodeVasete = tblGroupAshkhas_1.fldGroupId

						 where 
						  -- access kala limitation
						  tblKala.fldCodeGroup in (select code from @accesskala) and
						 dbo.tblRizeBargashtAzForoosh.fldType=@DataType  ANd dbo.tblRizeBargashtAzForoosh.fldDate  BETWEEN  @DateFrom  AND  @DateTo 

         if @ListCodeKala<>''
		  begin
		   declare @StrDeleteKala varchar(5000)
		    set  @StrDeleteKala='delete from #TempRizeBargashtAzForoosh 
		            where fldCodeKala NOT IN ('+ @ListCodeKala +')'
					execute(@StrDeleteKala)
		  end

		  if @ListGroupKala<>''
		   begin
		     declare @StrDeleteGroupKala varchar(5000)
		       set  @StrDeleteGroupKala='delete from #TempRizeBargashtAzForoosh 
		            where '+ @ListGroupKala + ''
					execute(@StrDeleteGroupKala)
		   end


		   if @ListCodeAshkhas <>''
		    begin
		     declare @StrDeleteAshkhas varchar(5000)
		      set  @StrDeleteAshkhas='delete from #TempRizeBargashtAzForoosh 
		            where fldCodeTafsili NOT IN ('+ @ListCodeAshkhas +')'
					execute(@StrDeleteAshkhas)
		    end


			if @ListGroupAshkhas<>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempRizeBargashtAzForoosh 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end

			if @ListCodeAnbar <>''
		     begin
		      declare @StrDeleteAnbar varchar(5000)
		       set  @StrDeleteAnbar='delete from #TempRizeBargashtAzForoosh 
		            where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
					execute(@StrDeleteAnbar)
		     end


			if @ListCodeVisitor<>''
		     begin
		      declare @StrDeleteVisitor varchar(5000)
		       set  @StrDeleteVisitor='delete from #TempRizeBargashtAzForoosh 
		            where '+ @ListCodeVisitor + ''
					execute(@StrDeleteVisitor)
		     end
-- ###############################################################
-- ######################### Access ashkhas limitation
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 

delete #TempRizeBargashtAzForoosh where fldCodeTafsili not in(select code from @accessCodes)
-- ###############################################################

if @FlagSort='0'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,

case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed ,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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 #TempRizeBargashtAzForoosh	ORDER BY fldDate ASC
 end
 
 	
if @FlagSort='1'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed ,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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 #TempRizeBargashtAzForoosh	ORDER BY fldShomareSanad ASC
 end
 

if @FlagSort='2'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed ,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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 #TempRizeBargashtAzForoosh	ORDER BY fldCodeKala ASC
 end
 

if @FlagSort='3'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed ,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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 #TempRizeBargashtAzForoosh	ORDER BY fldNameKala ASC
 end
 
 if @FlagSort='4'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed ,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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 #TempRizeBargashtAzForoosh	ORDER BY fldCodeTafsili ASC
 end
 

if @FlagSort='5'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed ,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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 #TempRizeBargashtAzForoosh	ORDER BY fldSharheTafzili  ASC

end
 
END
GO

-- ===============================================
-- SP: [dbo].[ShowList_ReportJaameFoRoosh_RizeForoosh_final]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowList_ReportJaameFoRoosh_RizeForoosh_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowList_ReportJaameFoRoosh_RizeForoosh_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ShowList_ReportJaameFoRoosh_RizeForoosh_final]
	@userCode bigint,
	@ListCodeKala varchar(5000)=null,
	@ListGroupKala varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListGroupAshkhas2 varchar(5000)=null,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeVisitor varchar(5000)=null,
	@ListCodeAnbar varchar(5000)=null,
	@DataType varchar(40),
	@DateFrom varchar(8),
	@DateTo varchar(8),
	@arzesheafzoode nvarchar(1),
	@Feezero nvarchar(1),
	@eshantion nvarchar(1),
	@FlagSort Varchar(5),
	@Rabet Varchar(15),
	@CodeMeli int
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) COLLATE Persian_100_CI_AS,
fldShomareFactor Nvarchar(30) COLLATE Persian_100_CI_AS,
fldCodeTafsili Nvarchar(30) COLLATE Persian_100_CI_AS,
fldSharheTafzili Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeAnbar Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeKala bigint,
fldNameKala Nvarchar(200) COLLATE Persian_100_CI_AS,
fldGhymatMasrafkonande Nvarchar(100) COLLATE Persian_100_CI_AS,
fldSharhKala Nvarchar(250) COLLATE Persian_100_CI_AS,
fldTedadCarton Nvarchar(100) COLLATE Persian_100_CI_AS, 
fldTedadJoz Nvarchar(100) COLLATE Persian_100_CI_AS,
fldFeeJoz Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldFeeYekCarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldFeeKol Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldDarsadTakhfif Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldMablaghTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldFeeVahed1BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS,
fldFeeVahed2BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldArzeshAfzode decimal(18,0), 
fldFeeKolBadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldeshantion nvarchar(50)  COLLATE Persian_100_CI_AS,
fldMablaghKhales decimal(18,0), 
fldType Nvarchar(50) COLLATE Persian_100_CI_AS, 
fldDate int, 
fldGroupId Nvarchar(30) COLLATE Persian_100_CI_AS,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeVasete Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameVasete Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldCodeGroupAshkhas2 Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldGroupNameAshkhas Nvarchar(200) COLLATE Persian_100_CI_AS,
fldGroupNameAshkhas2 Nvarchar(200) COLLATE Persian_100_CI_AS,
fldTedadJozKarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldCity Nvarchar(50) COLLATE Persian_100_CI_AS,
fldAddress Nvarchar(200) COLLATE Persian_100_CI_AS,
fldTell nvarchar(50)  COLLATE Persian_100_CI_AS,
fldCodemeli nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeRabet Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameRabet Nvarchar(200) COLLATE Persian_100_CI_AS,
)
end

------------------

-- Start getting KalaAccess

declare @accessKala table(code bigint)

insert into @accessKala(code)
--exec ZSP_GetKalaAccesses @userCode
exec [ZSP_GetAccessableGroupKalaCode] @userCode

INSERT INTO #TempRizeForoosh(fldShomareSanad ,
fldShomareFactor ,
fldCodeTafsili ,
fldSharheTafzili , 
fldCodeAnbar , 
fldNameAnbar , 
fldCodeKala ,
fldNameKala ,
fldGhymatMasrafkonande,
fldSharhKala ,
fldTedadCarton , 
fldTedadJoz ,
fldFeeJoz , 
fldFeeYekCarton ,
fldFeeKol , 
fldDarsadTakhfif , 
fldMablaghTakhfif , 
fldFeeVahed1BadAzTakhfif ,
fldFeeVahed2BadAzTakhfif , 
fldArzeshAfzode , 
fldFeeKolBadAzTakhfif , 
fldeshantion,
fldMablaghKhales , 
fldType, 
fldDate, 
fldGroupId,
fldGroupName, 
fldCodeVasete,
fldNameVasete,
fldCodeRabet,
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,fldeshantion, dbo.tblRizeForoosh.fldMablaghKhales, dbo.tblRizeForoosh.fldType, dbo.tblRizeForoosh.fldDate, 
                         dbo.tblGroupKala.fldGroupId, dbo.tblGroupKala.fldGroupName, dbo.tblRizeForoosh.fldCodeVasete, dbo.tblTafzili.fldSharheTafzili AS fldNameVasete,  dbo.tblRizeForoosh.fldCodeVasete2,
                         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 
						 -- here we adding access kala limitation
						 (tblKala.fldCodeGroup in (select code from @accessKala)) and 
						 dbo.tblRizeForoosh.fldType=@DataType  ANd dbo.tblRizeForoosh.fldDate  BETWEEN  @DateFrom  AND  @DateTo 
         


update #TempRizeForoosh set fldCodeGroupAshkhas2= tblTafzili.fldCodeGroup2 from tblTafzili where #TempRizeForoosh.fldCodeTafsili=tblTafzili.fldCodeTafzili
update #TempRizeForoosh  set fldCodeGroupAshkhas2='' where fldCodeGroupAshkhas2 is null
update #TempRizeForoosh  set fldGroupNameAshkhas2=tblGroupAshkhas.fldGroupName from tblGroupAshkhas where #TempRizeForoosh.fldCodeGroupAshkhas2=tblGroupAshkhas.fldGroupId
update #TempRizeForoosh  set fldGroupNameAshkhas2='' where fldGroupNameAshkhas2 is null

--select * from tbltafzili
--select * from tblGroupAshkhas


		 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 @ListGroupAshkhas2<>''
		      begin
		       declare @StrDeleteGroup2Ashkhas varchar(5000)
		        set  @StrDeleteGroup2Ashkhas='delete from #TempRizeForoosh 
		            where '+ @ListGroupAshkhas2 + ''
					execute(@StrDeleteGroup2Ashkhas)
		      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

	
-- ##################################################
-- ####Group ASHKHAS Limitation######################
-- ##################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 

-- ##################################################

delete from #TempRizeForoosh where fldCodeTafsili not in (select code from @accessCodes)

-- ##################################################

update #TempRizeForoosh set fldNameRabet='',fldCodeRabet='' where fldCodeRabet is NULL
update #TempRizeForoosh set fldNameRabet=tblTafzili.fldSharheTafzili from tbltafzili where #TempRizeForoosh.fldCodeRabet=tblTafzili.fldCodeTafzili

update #TempRizeForoosh set fldCity=tblTafzili.fldCity,fldAddress=tblTafzili.fldAddress,fldCodemeli=tblTafzili.fldCodeMeli from tblTafzili where #TempRizeForoosh.fldCodeTafsili=tblTafzili.fldCodeTafzili
--update #TempRizeForoosh set fldTell=0


		update #TempRizeForoosh set fldTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempRizeForoosh.fldCodeTafsili=tbl5.fldCodeTafzili

update #TempRizeForoosh set fldArzeshAfzode=0 where fldArzeshAfzode is null
if @arzesheafzoode='1'
	delete #TempRizeForoosh where fldArzeshAfzode=0
else if @arzesheafzoode='0'
	delete #TempRizeForoosh where fldArzeshAfzode>0


update #TempRizeForoosh set fldMablaghKhales=0 where fldMablaghKhales is null
if @Feezero='1'
	delete #TempRizeForoosh where fldMablaghKhales>0
else if @Feezero='0'
	delete #TempRizeForoosh where fldMablaghKhales=0

update #TempRizeForoosh set fldeshantion='' where fldeshantion is null
if @eshantion='1'
	delete #TempRizeForoosh where fldeshantion<>'eshantion'
else if @eshantion='0'
	delete #TempRizeForoosh where fldeshantion='eshantion'


	if isnumeric(@Rabet )=1
		begin
			delete #TempRizeForoosh where fldCodeRabet=''
			delete #TempRizeForoosh where fldCodeRabet<>@Rabet
		end

if @CodeMeli=1 --باکدملی
	delete #TempRizeForoosh where isnumeric(fldCodemeli)=0
else if @CodeMeli=0 --بدون کد ملی
	delete #TempRizeForoosh where isnumeric(fldCodemeli)=1

if @FlagSort='0'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldeshantion,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldCodeGroupAshkhas2,
fldGroupNameAshkhas2,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
fldCodeRabet,
fldNameRabet,
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,
fldCity,
fldAddress,
fldTell,
fldCodemeli
From #TempRizeForoosh	ORDER BY fldDate,Convert(dec,fldShomareFactor) ASC
 end
 
 	
if @FlagSort='1'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldeshantion,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldCodeGroupAshkhas2,
fldGroupNameAshkhas2,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
fldCodeRabet,
fldNameRabet,
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,
fldCity,
fldAddress,
fldTell,
fldcodemeli
From #TempRizeForoosh	ORDER BY Convert(dec,fldShomareSanad),Convert(dec,fldShomareFactor) ASC
 end
 

if @FlagSort='2'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldeshantion,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldCodeGroupAshkhas2,
fldGroupNameAshkhas2,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
fldCodeRabet,
fldNameRabet,
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,
fldCity,
fldAddress,
fldTell,
fldcodemeli
From #TempRizeForoosh	ORDER BY fldCodeKala,Convert(dec,fldShomareFactor) ASC
 end
 

if @FlagSort='3'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldeshantion,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldCodeGroupAshkhas2,
fldGroupNameAshkhas2,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
fldCodeRabet,
fldNameRabet,
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,
fldCity,
fldAddress,
fldTell,
fldcodemeli
From #TempRizeForoosh	ORDER BY fldNameKala ASC
 end
 
 if @FlagSort='4'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldeshantion,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldCodeGroupAshkhas2,
fldGroupNameAshkhas2,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
fldCodeRabet,
fldNameRabet,
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,
fldCity,
fldAddress,
fldTell,
fldCodemeli
From #TempRizeForoosh	ORDER BY Convert(dec,fldCodeTafsili),Convert(dec,fldShomareSanad) ASC
 end
 

if @FlagSort='5'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end as fldNameVahed2,
fldTedadCarton,
fldTedadJozKarton,
fldTedadJoz,
fldFeeJoz, 
fldFeeYekCarton,
fldFeeKol,
fldDarsadTakhfif, 
fldMablaghTakhfif,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldFeeKolBadAzTakhfif,
fldeshantion,
fldArzeshAfzode, 
fldGhymatMasrafkonande,
fldMablaghKhales, 
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldCodeGroupAshkhas2,
fldGroupNameAshkhas2,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar, 
fldCodeVasete,
fldNameVasete,
fldCodeRabet,
fldNameRabet,
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,
fldCity,
fldAddress,
fldTell,
fldCodemeli
From #TempRizeForoosh	ORDER BY fldSharheTafzili,Convert(dec,fldShomareFactor)  ASC
end
 
END
GO

-- ===============================================
-- SP: [dbo].[ShowList_ReportJaameFoRoosh_RizeForoosh_final_vasete2]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowList_ReportJaameFoRoosh_RizeForoosh_final_vasete2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowList_ReportJaameFoRoosh_RizeForoosh_final_vasete2] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ShowList_ReportJaameFoRoosh_RizeForoosh_final_vasete2]
	@userCode bigint,
	@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) COLLATE Persian_100_CI_AS,
fldShomareFactor Nvarchar(30) COLLATE Persian_100_CI_AS,
fldCodeTafsili Nvarchar(30) COLLATE Persian_100_CI_AS,
fldSharheTafzili Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeAnbar Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeKala bigint,
fldNameKala Nvarchar(200) COLLATE Persian_100_CI_AS,
fldGhymatMasrafkonande Nvarchar(100) COLLATE Persian_100_CI_AS,
fldSharhKala Nvarchar(250) COLLATE Persian_100_CI_AS,
fldTedadCarton Nvarchar(100) COLLATE Persian_100_CI_AS, 
fldTedadJoz Nvarchar(100) COLLATE Persian_100_CI_AS,
fldFeeJoz Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldFeeYekCarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldFeeKol Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldDarsadTakhfif Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldMablaghTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldFeeVahed1BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS,
fldFeeVahed2BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldArzeshAfzode Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldFeeKolBadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldMablaghKhales Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldType Nvarchar(50) COLLATE Persian_100_CI_AS, 
fldDate int, 
fldGroupId Nvarchar(30) COLLATE Persian_100_CI_AS,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeVasete Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameVasete Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldGroupNameAshkhas Nvarchar(200) COLLATE Persian_100_CI_AS,
fldTedadJozKarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldCity Nvarchar(50) COLLATE Persian_100_CI_AS,
fldAddress Nvarchar(200) COLLATE Persian_100_CI_AS,
fldTell nvarchar(50)  COLLATE Persian_100_CI_AS
)
end

------------------

-- Start getting KalaAccess

declare @accessKala table(code bigint)

insert into @accessKala(code)
--exec ZSP_GetKalaAccesses @userCode
exec [ZSP_GetAccessableGroupKalaCode] @userCode

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.fldCodeVasete2, 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.fldCodeVasete2 = dbo.tblTafzili.fldCodeTafzili LEFT OUTER JOIN
                         dbo.tblGroupAshkhas AS tblGroupAshkhas_1 ON dbo.tblRizeForoosh.fldCodeVasete2 = tblGroupAshkhas_1.fldGroupId

						 where 
						 -- here we adding access kala limitation
						 (tblKala.fldCodeGroup in (select code from @accessKala)) and 
						 dbo.tblRizeForoosh.fldType=@DataType  ANd dbo.tblRizeForoosh.fldDate  BETWEEN  @DateFrom  AND  @DateTo 
         
		 --select * from #TempRizeForoosh

		 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

	
-- ##################################################
-- ####Group ASHKHAS Limitation######################
-- ##################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 

-- ##################################################

delete from #TempRizeForoosh where fldCodeTafsili not in (select code from @accessCodes)

-- ##################################################


update #TempRizeForoosh set fldCity=tblTafzili.fldCity,fldAddress=tblTafzili.fldAddress from tblTafzili where #TempRizeForoosh.fldCodeTafsili=tblTafzili.fldCodeTafzili
--update #TempRizeForoosh set fldTell=0


		update #TempRizeForoosh set fldTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempRizeForoosh.fldCodeTafsili=tbl5.fldCodeTafzili


if @FlagSort='0'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizeForoosh	ORDER BY fldDate,Convert(dec,fldShomareFactor) ASC
 end
 
 	
if @FlagSort='1'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizeForoosh	ORDER BY Convert(dec,fldShomareSanad),Convert(dec,fldShomareFactor) ASC
 end
 

if @FlagSort='2'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizeForoosh	ORDER BY fldCodeKala,Convert(dec,fldShomareFactor) ASC
 end
 

if @FlagSort='3'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizeForoosh	ORDER BY fldNameKala ASC
 end
 
 if @FlagSort='4'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizeForoosh	ORDER BY Convert(dec,fldCodeTafsili),Convert(dec,fldShomareSanad) ASC
 end
 

if @FlagSort='5'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizeForoosh	ORDER BY fldSharheTafzili,Convert(dec,fldShomareFactor)  ASC
end
 
END
GO

-- ===============================================
-- SP: [dbo].[ShowList_ReportJaameKharid_BargashtAzRizeBargashtAzKharid_final]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowList_ReportJaameKharid_BargashtAzRizeBargashtAzKharid_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowList_ReportJaameKharid_BargashtAzRizeBargashtAzKharid_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ShowList_ReportJaameKharid_BargashtAzRizeBargashtAzKharid_final]
	@userCode bigint,
	@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..#TempRizeBargashtAzKharid') IS NOT NULL
 begin
	delete from  #TempRizeBargashtAzKharid
 end
else 
begin
create table #TempRizeBargashtAzKharid(

fldShomareSanad Nvarchar(30) COLLATE Persian_100_CI_AS,
fldShomareFactor Nvarchar(30) COLLATE Persian_100_CI_AS,
fldCodeTafsili Nvarchar(30) COLLATE Persian_100_CI_AS,
fldSharheTafzili Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeAnbar Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeKala bigint,
fldNameKala Nvarchar(200) COLLATE Persian_100_CI_AS,
fldGhymatMasrafkonande Nvarchar(100) COLLATE Persian_100_CI_AS,
fldSharhKala Nvarchar(250) COLLATE Persian_100_CI_AS,
fldTedadCarton Nvarchar(100) COLLATE Persian_100_CI_AS, 
fldTedadJoz Nvarchar(100) COLLATE Persian_100_CI_AS,
fldFeeJoz Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldFeeYekCarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldFeeKol Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldDarsadTakhfif Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldMablaghTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldFeeVahed1BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS,
fldFeeVahed2BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldArzeshAfzode Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldFeeKolBadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldMablaghKhales Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldType Nvarchar(50) COLLATE Persian_100_CI_AS, 
fldDate int, 
fldGroupId Nvarchar(30) COLLATE Persian_100_CI_AS,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldGroupNameAshkhas Nvarchar(200) COLLATE Persian_100_CI_AS,
fldTedadJozKarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldHamloNaghl  Nvarchar(100) COLLATE Persian_100_CI_AS
)
end

-- Get All AccessKala
declare @accessKala table(code bigint)

insert into @accessKala(code)
--exec ZSP_GetKalaAccesses @userCode
exec [ZSP_GetAccessableGroupKalaCode] @userCode


INSERT INTO #TempRizeBargashtAzKharid(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.tblRizeBargashtAzKharid.fldShomareSanad, dbo.tblRizeBargashtAzKharid.fldShomareFactor, dbo.tblRizeBargashtAzKharid.fldCodeTafsili, dbo.tblTafzili.fldSharheTafzili, 
                         dbo.tblRizeBargashtAzKharid.fldCodeAnbar, dbo.tblAnbar.fldNameAnbar, dbo.tblRizeBargashtAzKharid.fldCodeKala,
						 dbo.tblKala.fldNameKala,dbo.tblRizeBargashtAzKharid.fldGhymatMasrafkonande, dbo.tblRizeBargashtAzKharid.fldSharhKala, dbo.tblRizeBargashtAzKharid.fldTedadCarton, 
                         ABS(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.fldType, 
                         dbo.tblRizeBargashtAzKharid.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.tblRizeBargashtAzKharid.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.tblRizeBargashtAzKharid INNER JOIN
                         dbo.tblAnbar ON dbo.tblRizeBargashtAzKharid.fldCodeAnbar = dbo.tblAnbar.fldCode ON dbo.tblKala.fldCodeKala = dbo.tblRizeBargashtAzKharid.fldCodeKala ON 
                         dbo.tblTafzili.fldCodeTafzili = dbo.tblRizeBargashtAzKharid.fldCodeTafsili

						 where 
						 -- add kala access limitation
						 tblKala.fldCodeGroup in (select code from @accesskala) and
						 dbo.tblRizeBargashtAzKharid.fldType=@DataType  ANd dbo.tblRizeBargashtAzKharid.fldDate  BETWEEN  @DateFrom  AND  @DateTo 

         if @ListCodeKala<>''
		  begin
		   declare @StrDeleteKala varchar(5000)
		    set  @StrDeleteKala='delete from #TempRizeBargashtAzKharid
		            where fldCodeKala NOT IN ('+ @ListCodeKala +')'
					execute(@StrDeleteKala)
		  end

		  if @ListGroupKala<>''
		   begin
		     declare @StrDeleteGroupKala varchar(5000)
		       set  @StrDeleteGroupKala='delete from #TempRizeBargashtAzKharid 
		            where '+ @ListGroupKala + ''
					execute(@StrDeleteGroupKala)
		   end


		   if @ListCodeAshkhas <>''
		    begin
		     declare @StrDeleteAshkhas varchar(5000)
		      set  @StrDeleteAshkhas='delete from #TempRizeBargashtAzKharid 
		            where fldCodeTafsili NOT IN ('+ @ListCodeAshkhas +')'
					execute(@StrDeleteAshkhas)
		    end


			if @ListGroupAshkhas<>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempRizeBargashtAzKharid 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end

			if @ListCodeAnbar <>''
		     begin
		      declare @StrDeleteAnbar varchar(5000)
		       set  @StrDeleteAnbar='delete from #TempRizeBargashtAzKharid 
		            where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
					execute(@StrDeleteAnbar)
		     end


-- #######################################################################
-- Group Ashkhas limitation
-- #######################################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 

delete from #TempRizeBargashtAzKharid where fldCodeTafsili not in (select code from @accessCodes)
-- #######################################################################


if @FlagSort='0'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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 #TempRizeBargashtAzKharid	ORDER BY fldDate ASC
 end
 
 	
if @FlagSort='1'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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 #TempRizeBargashtAzKharid	ORDER BY fldShomareSanad ASC
 end
 

if @FlagSort='2'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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 #TempRizeBargashtAzKharid	ORDER BY fldCodeKala ASC
 end
 

if @FlagSort='3'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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 #TempRizeBargashtAzKharid	ORDER BY fldNameKala ASC
 end
 
 if @FlagSort='4'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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 #TempRizeBargashtAzKharid	ORDER BY fldCodeTafsili ASC
 end
 

if @FlagSort='5'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
1,
2,
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 #TempRizeBargashtAzKharid	ORDER BY fldSharheTafzili  ASC
end
 
END
GO

-- ===============================================
-- SP: [dbo].[ShowList_ReportJaameKharid_RizeKharid_final]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowList_ReportJaameKharid_RizeKharid_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowList_ReportJaameKharid_RizeKharid_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ShowList_ReportJaameKharid_RizeKharid_final]
	@userCode bigint,
	@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) COLLATE Persian_100_CI_AS,
fldShomareFactor Nvarchar(30) COLLATE Persian_100_CI_AS,
fldCodeTafsili Nvarchar(30) COLLATE Persian_100_CI_AS,
fldSharheTafzili Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeAnbar Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeKala bigint,
fldNameKala Nvarchar(200) COLLATE Persian_100_CI_AS,
fldGhymatMasrafkonande Nvarchar(100) COLLATE Persian_100_CI_AS,
fldSharhKala Nvarchar(250) COLLATE Persian_100_CI_AS,
fldTedadCarton Nvarchar(100) COLLATE Persian_100_CI_AS, 
fldTedadJoz Nvarchar(100) COLLATE Persian_100_CI_AS,
fldFeeJoz Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldFeeYekCarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldFeeKol Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldDarsadTakhfif Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldMablaghTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldFeeVahed1BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS,
fldFeeVahed2BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldArzeshAfzode Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldFeeKolBadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldMablaghKhales Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldType Nvarchar(50) COLLATE Persian_100_CI_AS, 
fldDate int, 
fldGroupId Nvarchar(30) COLLATE Persian_100_CI_AS,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldGroupNameAshkhas Nvarchar(200) COLLATE Persian_100_CI_AS,
fldTedadJozKarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldHamloNaghl  Nvarchar(100) COLLATE Persian_100_CI_AS
)
end

-- Get All AccessKala
declare @accessKala table(code bigint)
insert into @accessKala(code)
--exec ZSP_GetKalaAccesses @userCode
exec [ZSP_GetAccessableGroupKalaCode] @userCode

-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodesAshkhas table(code bigint)
insert into @accessCodesAshkhas select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################


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 
						 -- add kala access limitation
						 tblKala.fldCodeGroup in (select code from @accesskala) and
						 -- ##################### Group Ashkhas Limitation
						 fldCodeTafsili in (select code from @accessCodesAshkhas) and
						 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,
--select cast when fldNameVahed=N'انتخاب کنید' then '' else '' end,
CASE  WHEN fldNameVahed=N'انتخاب کنید' THEN ''  END  as fldNameVahed,
CASE  WHEN fldNameVahed2=N'انتخاب کنید' THEN ''  END  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,
CASE  WHEN fldNameVahed=N'انتخاب کنید' THEN ''  END  as fldNameVahed,
--IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
CASE  WHEN fldNameVahed2=N'انتخاب کنید' THEN ''  END  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,
CASE  WHEN fldNameVahed=N'انتخاب کنید' THEN ''  END  as fldNameVahed,
--IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
CASE  WHEN fldNameVahed2=N'انتخاب کنید' THEN ''  END  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,
CASE  WHEN fldNameVahed=N'انتخاب کنید' THEN ''  END  as fldNameVahed,
--IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
CASE  WHEN fldNameVahed2=N'انتخاب کنید' THEN ''  END  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,
CASE  WHEN fldNameVahed=N'انتخاب کنید' THEN ''  END  as fldNameVahed,
--IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
CASE  WHEN fldNameVahed2=N'انتخاب کنید' THEN ''  END  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,
CASE  WHEN fldNameVahed=N'انتخاب کنید' THEN ''  END  as fldNameVahed,
--IIF(fldNameVahed2=N'انتخاب کنید' ,'',fldNameVahed2) as fldNameVahed2,
CASE  WHEN fldNameVahed2=N'انتخاب کنید' THEN ''  END  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

-- ===============================================
-- SP: [dbo].[ShowList_ReportJaamePisiPishFactor_final]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowList_ReportJaamePisiPishFactor_final', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowList_ReportJaamePisiPishFactor_final] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ShowList_ReportJaamePisiPishFactor_final]
	@userCode bigint,
	@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..#TempRizePishPishFactor') IS NOT NULL
 begin
	delete from  #TempRizePishPishFactor
 end
else 
begin
create table #TempRizePishPishFactor(

fldShomareSanad Nvarchar(30) COLLATE Persian_100_CI_AS,
fldShomareFactor Nvarchar(30) COLLATE Persian_100_CI_AS,
fldCodeTafsili Nvarchar(30) COLLATE Persian_100_CI_AS,
fldSharheTafzili Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeAnbar Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeKala bigint,
fldNameKala Nvarchar(200) COLLATE Persian_100_CI_AS,
fldGhymatMasrafkonande Nvarchar(100) COLLATE Persian_100_CI_AS,
fldSharhKala Nvarchar(250) COLLATE Persian_100_CI_AS,
fldTedadCarton Nvarchar(100) COLLATE Persian_100_CI_AS, 
fldTedadJoz Nvarchar(100) COLLATE Persian_100_CI_AS,
fldFeeJoz Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldFeeYekCarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldFeeKol Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldDarsadTakhfif Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldMablaghTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldFeeVahed1BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS,
fldFeeVahed2BadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldArzeshAfzode Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldFeeKolBadAzTakhfif Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldMablaghKhales Nvarchar(40) COLLATE Persian_100_CI_AS, 
fldType Nvarchar(50) COLLATE Persian_100_CI_AS, 
fldDate int, 
fldGroupId Nvarchar(30) COLLATE Persian_100_CI_AS,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeVasete Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameVasete Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldGroupNameAshkhas Nvarchar(200) COLLATE Persian_100_CI_AS,
fldTedadJozKarton Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldCity Nvarchar(50) COLLATE Persian_100_CI_AS,
fldAddress Nvarchar(200) COLLATE Persian_100_CI_AS,
fldTell nvarchar(50)  COLLATE Persian_100_CI_AS
)
end

------------------

-- Start getting KalaAccess

declare @accessKala table(code bigint)

insert into @accessKala(code)
--exec ZSP_GetKalaAccesses @userCode
exec [ZSP_GetAccessableGroupKalaCode] @userCode

INSERT INTO #TempRizePishPishFactor(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.tblRizePishPishForoosh.fldShomareSanad, dbo.tblRizePishPishForoosh.fldShomareFactor, dbo.tblRizePishPishForoosh.fldCodeTafsili, tblTafzili_1.fldSharheTafzili, 
                         dbo.tblRizePishPishForoosh.fldCodeAnbar, dbo.tblAnbar.fldNameAnbar, dbo.tblRizePishPishForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblKala.fldGhymatMasrafkonande, 
                         dbo.tblRizePishPishForoosh.fldSharhKala, dbo.tblRizePishPishForoosh.fldTedadCarton,ABS(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.fldType, dbo.tblRizePishPishForoosh.fldDate, 
                         dbo.tblGroupKala.fldGroupId, dbo.tblGroupKala.fldGroupName, dbo.tblRizePishPishForoosh.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.tblRizePishPishForoosh INNER JOIN
                         dbo.tblAnbar ON dbo.tblRizePishPishForoosh.fldCodeAnbar = dbo.tblAnbar.fldCode INNER JOIN
                         dbo.tblKala ON dbo.tblRizePishPishForoosh.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.tblRizePishPishForoosh.fldCodeTafsili = tblTafzili_1.fldCodeTafzili LEFT OUTER JOIN
                         dbo.tblTafzili ON dbo.tblRizePishPishForoosh.fldCodeVasete = dbo.tblTafzili.fldCodeTafzili LEFT OUTER JOIN
                         dbo.tblGroupAshkhas AS tblGroupAshkhas_1 ON dbo.tblRizePishPishForoosh.fldCodeVasete = tblGroupAshkhas_1.fldGroupId

						 where 
						 -- here we adding access kala limitation
						 (tblKala.fldCodeGroup in (select code from @accessKala)) and 
						 dbo.tblRizePishPishForoosh.fldType=@DataType  ANd dbo.tblRizePishPishForoosh.fldDate  BETWEEN  @DateFrom  AND  @DateTo 
         
		 

		 if @ListCodeKala<>''
		  begin
		   declare @StrDeleteKala varchar(5000)
		    set  @StrDeleteKala='delete from #TempRizePishPishFactor 
		            where fldCodeKala NOT IN ('+ @ListCodeKala +')'
					execute(@StrDeleteKala)
		  end

		  if @ListGroupKala<>''
		   begin
		     declare @StrDeleteGroupKala varchar(5000)
		       set  @StrDeleteGroupKala='delete from #TempRizePishPishFactor 
		            where '+ @ListGroupKala + ''
					execute(@StrDeleteGroupKala)
		   end


		   if @ListCodeAshkhas <>''
		    begin
		     declare @StrDeleteAshkhas varchar(5000)
		      set  @StrDeleteAshkhas='delete from #TempRizePishPishFactor 
		            where fldCodeTafsili NOT IN ('+ @ListCodeAshkhas +')'
					execute(@StrDeleteAshkhas)
		    end


			if @ListGroupAshkhas<>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempRizePishPishFactor 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end

			if @ListCodeAnbar <>''
		     begin
		      declare @StrDeleteAnbar varchar(5000)
		       set  @StrDeleteAnbar='delete from #TempRizePishPishFactor 
		            where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
					execute(@StrDeleteAnbar)
		     end


			if @ListCodeVisitor<>''
		     begin
		      declare @StrDeleteVisitor varchar(5000)
		       set  @StrDeleteVisitor='delete from #TempRizePishPishFactor 
		            where '+ @ListCodeVisitor + ''
					execute(@StrDeleteVisitor)
		     end

	
-- ##################################################
-- ####Group ASHKHAS Limitation######################
-- ##################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 

-- ##################################################

delete from #TempRizePishPishFactor where fldCodeTafsili not in (select code from @accessCodes)

-- ##################################################


update #TempRizePishPishFactor set fldCity=tblTafzili.fldCity,fldAddress=tblTafzili.fldAddress from tblTafzili where #TempRizePishPishFactor.fldCodeTafsili=tblTafzili.fldCodeTafzili
--update #TempRizePishPishFactor set fldTell=0


		update #TempRizePishPishFactor set fldTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempRizePishPishFactor.fldCodeTafsili=tbl5.fldCodeTafzili


if @FlagSort='0'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizePishPishFactor	ORDER BY fldDate,Convert(dec,fldShomareFactor) ASC
 end
 
 	
if @FlagSort='1'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizePishPishFactor	ORDER BY Convert(dec,fldShomareSanad),Convert(dec,fldShomareFactor) ASC
 end
 

if @FlagSort='2'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizePishPishFactor	ORDER BY fldCodeKala,Convert(dec,fldShomareFactor) ASC
 end
 

if @FlagSort='3'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizePishPishFactor	ORDER BY fldNameKala ASC
 end
 
 if @FlagSort='4'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizePishPishFactor	ORDER BY Convert(dec,fldCodeTafsili),Convert(dec,fldShomareSanad) ASC
 end
 

if @FlagSort='5'
 begin
select fldShomareSanad,
fldShomareFactor,
fldCodeTafsili,
fldSharheTafzili,
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end 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,
fldCity,
fldAddress,
fldTell
From #TempRizePishPishFactor	ORDER BY fldSharheTafzili,Convert(dec,fldShomareFactor)  ASC
end
 
END
GO

-- ===============================================
-- SP: [dbo].[ShowList_TblTell_By_CodeTafsili_From_Form_Ashkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowList_TblTell_By_CodeTafsili_From_Form_Ashkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowList_TblTell_By_CodeTafsili_From_Form_Ashkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowList_TblTell_By_CodeTafsili_From_Form_Ashkhas]
@fldCodeTafsili nvarchar(10)
as
begin
SELECT        fldShomare
FROM          dbo.tblDaftarcheTell
where fldCodeTafzili=@fldCodeTafsili 
end
GO

-- ===============================================
-- SP: [dbo].[ShowList_TblTell_By_CodeTafsili_From_Form_Ashkhas_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowList_TblTell_By_CodeTafsili_From_Form_Ashkhas_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowList_TblTell_By_CodeTafsili_From_Form_Ashkhas_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowList_TblTell_By_CodeTafsili_From_Form_Ashkhas_WithUserCode]
@fldCodeTafsili nvarchar(10),
@userCode bigint
as
begin

-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################
-- ##########################################################



SELECT        fldShomare
FROM          dbo.tblDaftarcheTell
where fldCodeTafzili=@fldCodeTafsili 
and fldCodeTafzili in (select code from @accessCodes)
end
GO

-- ===============================================
-- SP: [dbo].[ShowList_Vasteha]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowList_Vasteha', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowList_Vasteha] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[showListAshkhasVisitorWithMobile]
-- ===============================================
IF OBJECT_ID(N'dbo.showListAshkhasVisitorWithMobile', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[showListAshkhasVisitorWithMobile] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[showListAshkhasVisitorWithMobile](@CodeVasete bigint)
as
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
create table #tmp(
	fldCodeTafzili bigint,
	fldSharheTafzili nvarchar(250),
	fldAddress nvarchar(250),
	fldMobile nvarchar(50)
)

if @CodeVasete<>0
	insert into #tmp
		(fldCodeTafzili,fldSharheTafzili,fldAddress)
			select fldCodeTafzili,fldSharheTafzili,fldAddress from tblTafzili Where fldVisitor=@CodeVasete
else
	insert into #tmp
		(fldCodeTafzili,fldSharheTafzili,fldAddress)
			select fldCodeTafzili,fldSharheTafzili,fldAddress from tblTafzili 

	update #tmp set fldMobile=tbl1.fldShomare from 
		(select fldCodeTafzili,fldshomare from tblDaftarcheTell where fldSms='فعال') as tbl1
		where #tmp.fldCodeTafzili=tbl1.fldCodeTafzili

	select 	fldCodeTafzili ,fldSharheTafzili ,fldAddress ,fldMobile from #tmp
end
GO

-- ===============================================
-- SP: [dbo].[ShowListEbteda_Doreh_Ashkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListEbteda_Doreh_Ashkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListEbteda_Doreh_Ashkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowListeDasteCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListeDasteCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListeDasteCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListeDasteCheck]
@CodeBank bigint

as
begin
	SELECT        ID, fldCodeBank, fldShobe, fldShomareCheck, fldShomareHesab
		FROM            tblDasteCheck
		WHERE        (fldCodeBank = @CodeBank)
		ORDER BY fldShomareCheck
end
GO

-- ===============================================
-- SP: [dbo].[ShowListEnteghal_Kala_Anbar]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListEnteghal_Kala_Anbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListEnteghal_Kala_Anbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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.fldTedadCarton, dbo.tblRizeForoosh.fldSharhKala,  
                         dbo.tblKala.fldCodeKala AS fldCodeKala,tblRizeForoosh.fldDateEngheza as fldDateEngheza
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

-- ===============================================
-- SP: [dbo].[ShowListePersonel]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListePersonel', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListePersonel] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ShowListePersonel] 
AS

IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN
	CREATE TABLE #tmpSooratHesab2(
	[ID] [bigint]  NOT NULL,
	[fldSharheTafzili] [nvarchar](200)  COLLATE Persian_100_CI_AS,
	[fldCodeTafzili][nvarchar](200)  COLLATE Persian_100_CI_AS,
	[fldOstan] [nvarchar](50)  COLLATE Persian_100_CI_AS,
	[fldCity] [nvarchar](50) COLLATE Persian_100_CI_AS,
	[fldAddress] [nvarchar](200) COLLATE Persian_100_CI_AS,
	[fldTell] [nvarchar](50) COLLATE Persian_100_CI_AS
	)

	Insert into	#tmpSooratHesab2(ID,fldSharheTafzili,fldCodeTafzili,fldOstan,fldCity,fldAddress)
			SELECT        ID, fldSharheTafzili, fldCodeTafzili, fldOstan, fldCity, fldAddress
				FROM            tblTafzili
					Where fldCodeNoe='0' and fldNoeVizitor=2

	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

-- ===============================================
-- SP: [dbo].[ShowListePersonelType]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListePersonelType', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListePersonelType] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ShowListePersonelType] 
@NoePersonel nvarchar(20)
AS

IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN
	CREATE TABLE #tmpSooratHesab2(
	[ID] [bigint]  NOT NULL,
	[fldSharheTafzili] [nvarchar](200) COLLATE Persian_100_CI_AS ,
	[fldCodeTafzili][nvarchar](200) COLLATE Persian_100_CI_AS ,
	[fldOstan] [nvarchar](50)  COLLATE Persian_100_CI_AS,
	[fldCity] [nvarchar](50) COLLATE Persian_100_CI_AS,
	[fldAddress] [nvarchar](200) COLLATE Persian_100_CI_AS,
	[fldTell] [nvarchar](50) COLLATE Persian_100_CI_AS
	)

	Insert into	#tmpSooratHesab2(ID,fldSharheTafzili,fldCodeTafzili,fldOstan,fldCity,fldAddress)
			SELECT        ID, fldSharheTafzili, fldCodeTafzili, fldOstan, fldCity, fldAddress
				FROM            tblTafzili
					Where fldCodeNoe='0' and fldNoePersonel=@NoePersonel

	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

-- ===============================================
-- SP: [dbo].[ShowListeUser]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListeUser', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListeUser] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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 where fldCode<>0
	else if @intType=1 -- مدیر
		Select ID, fldCode, fldUser, fldPassword, fldType from tblSecurity where fldType<>0 and fldCode<>0
	else if @intType=2 --کاربر
		Select ID, fldCode, fldUser, fldPassword, fldType from tblSecurity where fldCode=@CodeUser and fldCode<>0

END
GO

-- ===============================================
-- SP: [dbo].[ShowListGroupAshkhas_AfterAdd]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListGroupAshkhas_AfterAdd', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListGroupAshkhas_AfterAdd] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowListGroupAshkhas_AfterAdd_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListGroupAshkhas_AfterAdd_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListGroupAshkhas_AfterAdd_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListGroupAshkhas_AfterAdd_WithUserCode]
(
@ID  nvarchar(50),
@userCode bigint
)
as
begin

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableGroupAshkhasCode(@userCode) 

SELECT [fldGroupId]
      ,[fldGroupName]
  FROM [dbo].[tblGroupAshkhas]
  --where fldGroupId=convert(bigint,len(convert(nvarchar,[fldGroupId])=3))
  where 
  fldGroupId in (select code from @accessCodes ) and
  convert(nvarchar,[fldGroupId]) like @ID + '%' and  len(convert(nvarchar,[fldGroupId]))=(len(@ID)+3)
order by convert(nvarchar,[fldGroupId])
end
GO

-- ===============================================
-- SP: [dbo].[ShowListGroupAshkhas_ViSitors_ShowAll]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListGroupAshkhas_ViSitors_ShowAll', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListGroupAshkhas_ViSitors_ShowAll] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowListGroupAshkhas_ViSitors_ShowAll_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListGroupAshkhas_ViSitors_ShowAll_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListGroupAshkhas_ViSitors_ShowAll_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListGroupAshkhas_ViSitors_ShowAll_WithUserCode]
@userCode bigint
as
begin

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableGroupAshkhasCode(@userCode) 

select fldGroupId,fldGroupName   from tblGroupAshkhas
where 
fldGroupId in (select code from @accessCodes) and 
convert(nvarchar,[fldGroupId]) like convert(nvarchar,10100)+ '%' 
and len(convert(nvarchar,[fldGroupId]))=6
end
GO

-- ===============================================
-- SP: [dbo].[ShowListGroupKala_AfterAdd]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListGroupKala_AfterAdd', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListGroupKala_AfterAdd] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowListGruopAshkhas_All]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListGruopAshkhas_All', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListGruopAshkhas_All] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowListGruopAshkhas_All_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListGruopAshkhas_All_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListGruopAshkhas_All_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListGruopAshkhas_All_WithUserCode]
@userCode bigint
as
begin

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableGroupAshkhasCode(@userCode) 

SELECT [fldGroupId]
      ,[fldGroupName]
  FROM [dbo].[tblGroupAshkhas]
  --where fldGroupId=convert(bigint,len(convert(nvarchar,[fldGroupId])=3))
  where 
  fldGroupId in (select code from @accessCodes) and
  len(convert(nvarchar,[fldGroupId]))=3
order by convert(nvarchar,[fldGroupId])
end
GO

-- ===============================================
-- SP: [dbo].[showListGruopAshkhasBy_Enter]
-- ===============================================
IF OBJECT_ID(N'dbo.showListGruopAshkhasBy_Enter', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[showListGruopAshkhasBy_Enter] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[showListGruopAshkhasBy_Enter_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.showListGruopAshkhasBy_Enter_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[showListGruopAshkhasBy_Enter_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[showListGruopAshkhasBy_Enter_WithUserCode]
(@id  bigint,
@len  int,
@userCode bigint
)
as

if(exists(select [fldGroupId],fldGroupName from tblGroupAshkhas where convert(nvarchar,[fldGroupId]) like convert(nvarchar,@id)+ '%' and len(convert(nvarchar,[fldGroupId]))=@len+3))
begin

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableGroupAshkhasCode(@userCode) 

SELECT [fldGroupId]
      ,[fldGroupName]
  FROM [dbo].[tblGroupAshkhas]
  where 
  fldGroupId in (select code from @accessCodes) and
  convert(nvarchar,[fldGroupId]) like convert(nvarchar,@id)+ '%' and len(convert(nvarchar,[fldGroupId]))=@len+3
order by convert(nvarchar,[fldGroupId])
end
GO

-- ===============================================
-- SP: [dbo].[showListGruopAshkhasBy_Escap]
-- ===============================================
IF OBJECT_ID(N'dbo.showListGruopAshkhasBy_Escap', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[showListGruopAshkhasBy_Escap] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[showListGruopAshkhasBy_Escap_WithUserName]
-- ===============================================
IF OBJECT_ID(N'dbo.showListGruopAshkhasBy_Escap_WithUserName', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[showListGruopAshkhasBy_Escap_WithUserName] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[showListGruopAshkhasBy_Escap_WithUserName]
(@id  nvarchar(30),
@lenid  nvarchar(30),
@userCode bigint
)
as
begin


declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableGroupAshkhasCode(@userCode) 

if (@lenid >= 3)
begin
SELECT [fldGroupId]
      ,[fldGroupName]
FROM [dbo].[tblGroupAshkhas]
where 
fldGroupId in (select code from @accessCodes) and
convert(nvarchar,[fldGroupId]) like convert(nvarchar,@id)+ '%' and len(convert(nvarchar,[fldGroupId]))=@lenid+3
order by convert(nvarchar,[fldGroupId])

end


end
GO

-- ===============================================
-- SP: [dbo].[showListGruopAshkhasWithMobile]
-- ===============================================
IF OBJECT_ID(N'dbo.showListGruopAshkhasWithMobile', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[showListGruopAshkhasWithMobile] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[showListGruopAshkhasWithMobile](@Groupid  bigint,@len  int)
as
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
create table #tmp(
	fldCodeTafzili bigint,
	fldSharheTafzili nvarchar(250),
	fldAddress nvarchar(250),
	fldMobile nvarchar(50)
)

if @Groupid<>0
	insert into #tmp
		(fldCodeTafzili,fldSharheTafzili,fldAddress)
			select fldCodeTafzili,fldSharheTafzili,fldAddress from tblTafzili Where fldCodeGroup=@Groupid
else
	insert into #tmp
		(fldCodeTafzili,fldSharheTafzili,fldAddress)
			select fldCodeTafzili,fldSharheTafzili,fldAddress from tblTafzili 

	update #tmp set fldMobile=tbl1.fldShomare from 
		(select fldCodeTafzili,fldshomare from tblDaftarcheTell where fldSms='فعال') as tbl1
		where #tmp.fldCodeTafzili=tbl1.fldCodeTafzili

	select 	fldCodeTafzili ,fldSharheTafzili ,fldAddress ,fldMobile from #tmp
end
GO

-- ===============================================
-- SP: [dbo].[ShowListGruopKala_All]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListGruopKala_All', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListGruopKala_All] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowListGruopKala_All_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListGruopKala_All_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListGruopKala_All_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListGruopKala_All_WithUserCode]
@userCode bigint
as
begin

 declare @groups table(fldCode bigint)
 
  if ( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA') = 'True'
	begin
		 insert into @groups(fldCode)
			select fldKalaCode from tblGroupKalaAccess where fldUserCode=@userCode

			SELECT [fldGroupId]
				  ,[fldGroupName]
			  FROM [dbo].[tblGroupKala]			  
			  where len(convert(nvarchar,[fldGroupId]))=3  and fldGroupId in (select fldcode from @groups)
			order by convert(nvarchar,[fldGroupId])
		end
	else
		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

-- ===============================================
-- SP: [dbo].[showListGruopKalaBy_Enter]
-- ===============================================
IF OBJECT_ID(N'dbo.showListGruopKalaBy_Enter', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[showListGruopKalaBy_Enter] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[showListGruopKalaBy_Enter_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.showListGruopKalaBy_Enter_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[showListGruopKalaBy_Enter_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[showListGruopKalaBy_Enter_WithUserCode]
@id  bigint,
@len  int,
@userCode bigint
as

begin

 
  if ( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA') = 'True'
	begin
		declare @groups table(fldCode bigint)
		insert into @groups(fldCode)
			select fldKalaCode from tblGroupKalaAccess where fldUserCode=@userCode

		if(exists(select [fldGroupId],fldGroupName from tblGroupKala where fldGroupId in (select fldCode from @groups) and convert(nvarchar,[fldGroupId]) like convert(nvarchar,@id)+ '%' and len(convert(nvarchar,[fldGroupId]))=@len+3))
				SELECT [fldGroupId]
					  ,[fldGroupName]
				  FROM [dbo].[tblGroupKala]
				  where fldGroupId in (select fldCode from @groups) and convert(nvarchar,[fldGroupId]) like convert(nvarchar,@id)+ '%' and len(convert(nvarchar,[fldGroupId]))=@len+3
				order by convert(nvarchar,[fldGroupId])
	end
  else
	begin
		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 
	end


end
GO

-- ===============================================
-- SP: [dbo].[showListGruopKalaBy_Escap]
-- ===============================================
IF OBJECT_ID(N'dbo.showListGruopKalaBy_Escap', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[showListGruopKalaBy_Escap] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowListMojodi_Ebteda_Doreh]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListMojodi_Ebteda_Doreh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListMojodi_Ebteda_Doreh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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,tblRizeKharid.fldDateEngheza
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

-- ===============================================
-- SP: [dbo].[ShowListMojoodieAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListMojoodieAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListMojoodieAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListMojoodieAnbar]
  @userCode bigint,
  @MiangineKharid bigint output,
  @JameTedad bigint output,
  @lngSumTedadeKolSahih bigint output,
  @Order int,
  @Filter int,
  @ListCodeKala varchar(5000)=null,
  @ListCodeAnbar varchar(5000)=null,
  @ListCodeAnbarKhales ZT_CodeNumbers readonly,
  @ListGroupKala varchar(5000)=null,  
  @ListGroupKalaKhales ZT_CodeNumbers readonly,
  @DateTa bigint,
  @NoeFeeKharid int,
  @NoeAnbar nvarchar(20),
  @sefareshat  nvarchar(15)
--@nn nvarchar(10)

as

IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldTedadeVorood decimal(18, 2),
fldTedadeKhorooj decimal(18, 2),
fldTedadeJoz decimal(18, 2), 
fldTedadeKol decimal(18, 2), 
fldTedadDarKarton decimal(18, 2),
fldCodeAnbar int,
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 2),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldTedadeForoosh decimal(18, 2),
fldTedadeBargashtAzForoosh decimal(18, 2),
fldTedadeKharid decimal(18, 2),
fldTedadeBargashtAzKharid decimal(18, 2),
fldTedadeTolidVorood decimal(18, 2),
fldTedadeTolidKhorooj decimal(18, 2),
fldType nvarchar(20) COLLATE Persian_100_CI_AS
)


create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 2),
SumVoroodT nvarchar(200),
SumKhorooj decimal(18, 2),
SumKhoroojT nvarchar(200),
SumMande decimal(18, 2),
Mande nvarchar(200),
fldTedadDarKarton decimal(18, 2),
fldTedadKartonadadSahih decimal(18, 2),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadVoroodKarton decimal(18, 2),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadKhoroojKarton decimal(18, 2),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh decimal(18, 2),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldKharid bigint,
fldArzesheMojoodi bigint,
fldFeeForoosh bigint,
fldGhymatMasrafkonande dec(18,0),

fldTedadeForoosh decimal(18, 2),
fldTedadeForooshShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadeBargashtAzForoosh decimal(18, 2),
fldTedadeBargashtAzForooshShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadeKharid decimal(18, 2),
fldTedadeEnteghalVorood decimal(18, 2),
fldTedadeEnteghalKhorooj decimal(18, 2),
fldTedadeKharidShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadeBargashtAzKharid decimal(18, 2),
fldTedadeBargashtAzKharidShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadeTolidVorood decimal(18, 2),
fldTedadeTolidVoroodShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadeTolidKhorooj decimal(18, 2),
fldTedadeTolidKhoroojShow nvarchar(70) COLLATE Persian_100_CI_AS
)


declare @countGroup bigint
set @countGroup=0--( select count(CodeNumber) from @ListGroupKalaKhales)


--#####درست کردن فیلدهای ابتدای دوره
UPDATE       tblRizeKharid SET fldMablaghKhales = fldFeeKol WHERE        (fldType = 'mojodi_ebteda_doreh')

UPDATE       tblRizeKharid SET fldFeeKolBadAzTakhfif = fldFeeKol WHERE        (fldType = 'mojodi_ebteda_doreh')

update tblRizeKharid set fldFeeVahed1BadAzTakhfif=fldFeeJoz where  fldType='mojodi_ebteda_doreh'

update tblRizeKharid set fldFeeKolBadAzTakhfif=fldFeeVahed1BadAzTakhfif*fldTedadJoz where  fldType='mojodi_ebteda_doreh'
---######################################


if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeKharid, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) ) 
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeKharid, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz,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 Where flddate<=@DateTa   and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


	--else
--		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 Where flddate<=@DateTa  and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (@ListGroupKalaKhales) )

if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeTolidVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJozNahaei,fldTedadJozNahaei, 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            tblRizeTolid where fldType='mahsool' and flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeTolidVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJozNahaei,fldTedadJozNahaei, 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            tblRizeTolid where fldType='mahsool' and flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeBargashtAzForoosh, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeBargashtAzForoosh, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,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 Where flddate<=@DateTa   and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


-- برای حالتی که سفارشات از حواله گروهی سفارشات ویزیتور میاد
--کسر گردد پیش فاکتورهایی که حواله شده و برگشت نخورده اند و فاکتور نشده اند
if @sefareshat='sefareshat'
	if @countGroup >0
		INSERT INTO #TempMojoodieAnbar
								 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
								 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
		SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,fldTedadJoz, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
								 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
		FROM            tblRizePishPishForoosh Where 
					fldShomareFactor in 
					(SELECT        fldShomareFactor
						FROM            tblHavaleGoroohi
					WHERE        (fldType ='pishfactor') and fldbargasht is NULL and fldShomareFactor not in (select fldShomarePishFactor from tblforoosh where fldShomarePishFactor is not NULL  ))
						and   flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
	else
		INSERT INTO #TempMojoodieAnbar
								 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
								 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
		SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,fldTedadJoz, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
								 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
		FROM            tblRizePishPishForoosh Where 
					fldShomareFactor in 
					(SELECT        fldShomareFactor
						FROM            tblHavaleGoroohi
					WHERE        (fldType ='pishfactor') and fldbargasht is NULL and fldShomareFactor not in (select fldShomarePishFactor from tblforoosh where fldShomarePishFactor is not NULL  ))
					And flddate<=@DateTa   and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)



if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,fldTedadJoz, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
							 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
	FROM            tblRizHavaleHazine Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,fldTedadJoz, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
							 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
	FROM            tblRizHavaleHazine Where flddate<=@DateTa   and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeTolidKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJozAvalie ,fldTedadJozAvalie, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
							 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
	FROM            tblRizeTolid where fldType='avalie' and flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)   and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeTolidKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJozAvalie ,fldTedadJozAvalie, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
							 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
	FROM            tblRizeTolid where fldType='avalie' and flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeBargashtAzKharid, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)  and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeBargashtAzKharid, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


update #TempMojoodieAnbar set fldFeeForoosh=tblKala.fldFeeForoosh from tblKala Where #TempMojoodieAnbar.fldCodeKala=tblKala.fldCodeKala

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)



if @NoeAnbar='amani'
	delete #TempMojoodieAnbar where fldCodeAnbar<2000
else
	delete #TempMojoodieAnbar where fldCodeAnbar>=2000


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


--فیلتر تا قبل از تاریخ 

update #TempShowMojoodi set fldTedadeForoosh=0 where fldTedadeForoosh is Null
update #TempShowMojoodi set fldTedadeBargashtAzForoosh=0 where fldTedadeBargashtAzForoosh is Null
update #TempShowMojoodi set fldTedadeBargashtAzForoosh=0 where fldTedadeBargashtAzForoosh is Null
update #TempShowMojoodi set fldTedadeKharid=0 where fldTedadeKharid is Null
update #TempShowMojoodi set fldTedadeBargashtAzKharid=0 where fldTedadeBargashtAzKharid is Null
update #TempShowMojoodi set fldTedadeTolidVorood=0 where fldTedadeTolidVorood is Null
update #TempShowMojoodi set fldTedadeTolidKhorooj=0 where fldTedadeTolidKhorooj is Null
update #TempShowMojoodi set fldTedadeForoosh=0 where fldTedadeForoosh is Null


if @Filter=5
	begin
		Insert into #TempShowMojoodi
				(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid,fldFeeForoosh,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj)
			SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, 0 AS SumTedadeKhorooj, SUM(fldTedadeVorood ) AS sumMande, 
									 fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0,fldFeeForoosh ,sum(fldTedadeForoosh),sum(fldTedadeBargashtAzForoosh),sum(fldTedadeKharid),sum(fldTedadeBargashtAzKharid),sum(fldTedadeTolidVorood),sum(fldTedadeTolidKhorooj)
			FROM            #TempMojoodieAnbar where fldType='enteghal'
			GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh--,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj
	end
else
	begin
		Insert into #TempShowMojoodi
			(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid,fldFeeForoosh,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj)
		SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
								 fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0,fldFeeForoosh,sum(fldTedadeForoosh),sum(fldTedadeBargashtAzForoosh),sum(fldTedadeKharid),sum(fldTedadeBargashtAzKharid),sum(fldTedadeTolidVorood),sum(fldTedadeTolidKhorooj)
		FROM            #TempMojoodieAnbar
		GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh--,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj

		update #TempShowMojoodi set fldTedadeKharid = tbl1.sumtedad from (select sum(tblrizekharid.fldTedadJoz) as sumTedad,fldcodekala from tblRizeKharid where fldtype='Kharid' group by fldCodeKala) as tbl1
				where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala


--declare @StrUpdateAnbar varchar(5000), @enteghal varchar(5000)
--					set @enteghal='enteghal'
--					set @StrUpdateAnbar='select sum(tblrizekharid.fldTedadJoz) as sumTedad,fldcodekala from tblRizeKharid where fldtype ='''+ @enteghal +'''  group by fldCodeKala'
--					execute(@StrUpdateAnbar)

		if @ListCodeAnbar <>''
		     begin
		      declare @StrUpdateAnbar varchar(5000)
		       set  @StrUpdateAnbar='update #TempMojoodieAnbar 
		            where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
					execute(@StrDeleteAnbar)
					
					set @StrUpdateAnbar='update #TempShowMojoodi set fldTedadeEnteghalKhorooj= tbl1.sumtedad from (select sum(tblrizekharid.fldTedadJoz) as sumTedad,fldcodekala from tblRizeKharid where fldtype=''enteghal'' and fldCodeAnbar NOT IN ('+ @ListCodeAnbar +') group by fldCodeKala ) as tbl1
									where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala'
					execute(@StrUpdateAnbar)

					set @StrUpdateAnbar='update #TempShowMojoodi set fldTedadeEnteghalVorood  = tbl1.sumtedad from (select sum(tblRizeForoosh.fldTedadJoz) as sumTedad,fldcodekala from tblRizeForoosh where fldtype=''enteghal'' and fldCodeAnbar NOT IN ('+ @ListCodeAnbar +') group by fldCodeKala ) as tbl1
									where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala'
					execute(@StrUpdateAnbar)

					set @StrUpdateAnbar='update #TempShowMojoodi set fldTedadeForoosh= tbl1.sumtedad from (select sum(tblRizeForoosh.fldTedadJoz) as sumTedad,fldcodekala from tblRizeForoosh where fldtype=''Foroosh'' and fldCodeAnbar  IN ('+ @ListCodeAnbar +') group by fldCodeKala ) as tbl1
									where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala'
					--set @StrUpdateAnbar='update #TempShowMojoodi set fldTedadeForoosh= 555'
									
					execute(@StrUpdateAnbar)

			 end
		else
			begin
					update #TempShowMojoodi set fldTedadeEnteghalKhorooj  = tbl1.sumtedad from (select sum(tblrizekharid.fldTedadJoz) as sumTedad,fldcodekala from tblRizeKharid where fldtype='enteghal' group by fldCodeKala) as tbl1
							where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala

					update #TempShowMojoodi set fldTedadeEnteghalVorood= tbl1.sumtedad from (select sum(tblRizeForoosh.fldTedadJoz) as sumTedad,fldcodekala from tblRizeForoosh where fldtype='enteghal' group by fldCodeKala) as tbl1
							where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala

					update #TempShowMojoodi set fldTedadeForoosh= tbl1.sumtedad from (select sum(tblRizeForoosh.fldTedadJoz) as sumTedad,fldcodekala from tblRizeForoosh where fldtype='Foroosh' group by fldCodeKala ) as tbl1
							where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala
			end
	end


update #TempShowMojoodi set Mande=SumMande,SumVoroodT=SumVorood,SumKhoroojT=SumKhorooj
update #TempShowMojoodi set Mande=LEFT(Convert(varchar,SumMande),len(Convert(varchar,SumMande))-3) where right(convert(varchar,SumMande),2)='00'
update #TempShowMojoodi set SumVoroodT=LEFT(Convert(varchar,SumVorood),len(Convert(varchar,SumVorood))-3) where right(convert(varchar,SumVorood),2)='00'
update #TempShowMojoodi set SumKhoroojT=LEFT(Convert(varchar,SumKhorooj),len(Convert(varchar,SumKhorooj))-3) where right(convert(varchar,SumKhorooj),2)='00'

--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(Convert(dec, SumMande), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadVoroodKartonShow=Convert(varchar,floor(SumVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,SumVorood), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadKhoroojKartonShow=Convert(varchar,floor(SumKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,Sumkhorooj), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0


update #TempShowMojoodi Set fldTedadDarKartonShow=Convert(varchar,floor(SumMande / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec, SumMande), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0


--update #TempShowMojoodi Set fldTedadeForooshShow=Convert(varchar,floor(SumMande / fldTedadeForoosh)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec, SumMande), fldTedadDarKarton) } ) + ' ' + fldNameVahed
--	where fldTedadDarKarton>0




--fldTedadeBargashtAzForooshShow
--fldTedadeKharidShow

--fldTedadeBargashtAzKharidShow

--fldTedadeTolidVoroodShow

--fldTedadeTolidKhoroojShow



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 @NoeFeeKharid=1 --میانگین خرید
	begin
		update #TempShowMojoodi set fldKharid=tbl1.Miangin from
		(SELECT        ROUND(SUM(fldFeeKolBadAzTakhfif) / SUM(fldTedadJoz), 0) AS Miangin, fldCodeKala
		FROM            tblRizeKharid
		where fldType<>'enteghal' and fldDate <= @DateTa 
		GROUP BY fldCodeKala
		having         SUM(fldTedadJoz)>0 
		) as tbl1
		where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala  


		update #TempShowMojoodi set fldKharid=tbl1.Miangin from
			(SELECT        ROUND(SUM(fldFeeKol) / SUM(fldTedadJozNahaei), 0) AS Miangin, fldCodeKala
			FROM            tblRizeTolid
			where fldType<>'enteghal' and fldDate <= @DateTa 
			GROUP BY fldCodeKala
			having         SUM(fldTedadJozNahaei)>0 
			) as tbl1
			where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala  
		end
else if @NoeFeeKharid=2 --آخرین فی خرید
	begin
	--update #TempShowMojoodi set fldKharid=ROUND((tblRizeKharid.fldFeeKol) / (tblRizeKharid.fldTedadJoz), 0) from
	--	tblRizeKharid where  tblRizeKharid.fldCodeKala=#TempShowMojoodi.fldCodeKala 
	
		DECLARE @t TABLE(
		UniqueID INT,
		fldCodeKala bigint,
		[Fee] decimal(18,0),
		fldDate BIGINT
		);

		insert into @t
			(fldCodeKala,[Fee],fldDate)
			Select fldCodeKala, ROUND((tblRizeKharid.fldFeeKolBadAzTakhfif) / (tblRizeKharid.fldTedadJoz), 0),fldDATE from tblRizeKharid where fldType<>'enteghal' and tblRizeKharid.fldTedadJoz>0 and fldDate <= @DateTa 


		update #TempShowMojoodi set fldKharid=tbl1.[Fee] from 
			(SELECT t.fldCodeKala,MAX(t.[Fee]) AS [Fee],t.fldDate
			FROM @t t
			INNER JOIN(
				SELECT MAX(fldDate) AS fldDate,fldCodeKala
				FROM @t t
				GROUP BY fldCodeKala
			) AS t2
			ON t.[fldDate] = t2.[fldDate] 
				AND t.[fldCodeKala] = t2.fldCodeKala
			GROUP BY 
				t.fldCodeKala,
				t.[fldDate])as tbl1
			Where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala




		insert into @t
			(fldCodeKala,[Fee],fldDate)
			Select fldCodeKala, ROUND((tblRizeTolid.fldFeeKol) / (tblRizeTolid.fldTedadJozNahaei), 0),fldDATE from tblRizeTolid where fldType<>'enteghal' and tblRizeTolid.fldTedadJozNahaei>0 and fldDate <= @DateTa 


		update #TempShowMojoodi set fldKharid=tbl1.[Fee] from 
			(SELECT t.fldCodeKala,MAX(t.[Fee]) AS [Fee],t.fldDate
			FROM @t t
			INNER JOIN(
				SELECT MAX(fldDate) AS fldDate,fldCodeKala
				FROM @t t
				GROUP BY fldCodeKala
			) AS t2
			ON t.[fldDate] = t2.[fldDate] 
				AND t.[fldCodeKala] = t2.fldCodeKala
			GROUP BY 
				t.fldCodeKala,
				t.[fldDate])as tbl1
			Where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala

	end

else if @NoeFeeKharid=3 --في فروش
	begin
		update #TempShowMojoodi set fldKharid=fldFeeForoosh
	end
	



--پاک کردن گروه کالاهایی که در گزارش نیستن
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

----انتقال کالا
--if @Filter=4
--		delete from #TempShowMojoodi Where  fldtype<>'enteghal'




			--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)


  delete #TempShowMojoodi where fldNameKala='NameKala'
  
  -- Group Kala access
 Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA')
  if @value = 'True'
  Begin -- Limitation Active  
	-- Get All AccessKala
	declare @accesskala table(code bigint)
	insert into @accesskala 
	exec [ZSP_GetKalaAccesses] @userCode

	delete #TempShowMojoodi where fldCodeGroup not in (select code from @accesskala)
end

 Set @Select='Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi'

--Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	--fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid ,@strorder
	--from #TempShowMojoodi


--محاسبه ارزش موجودی هر کالا
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

	

	


update #TempShowMojoodi set fldTedadKartonadadSahih=(SumMande/fldTedadDarKarton)   Where fldTedadDarKarton>0
update #TempShowMojoodi set fldTedadKartonadadSahih=0 Where isnumeric(fldTedadKartonadadSahih)=0
set @lngSumTedadeKolSahih=(Select Sum(fldTedadKartonadadSahih) from #TempShowMojoodi)

update #TempShowMojoodi set fldGhymatMasrafkonande=tblKala.fldGhymatMasrafkonande from tblKala where tblKala.fldCodeKala=#TempShowMojoodi.fldCodeKala


update #TempShowMojoodi Set fldTedadDarKartonShow=convert(varchar,(-1)*Convert(varchar,floor((-1)*convert(dec,Mande) / convert(dec,fldTedadDarKarton)))) + ' کل ' +  Convert(varchar, { fn MOD(Convert(dec, Mande), convert(dec,fldTedadDarKarton)) } )  +  ' جز '
where convert(dec,Mande)<0 and fldTedadDarKarton>0

Set @JameTedad=(Select Sum(SumMande)  from #TempShowMojoodi Where SumMande>0)
if   @JameTedad is null
	set @JameTedad=0

if @Order=0 
	--set @StrOrder=' order by fldCodeKala'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by fldCodeKala
else if @order=1 	
	--set @StrOrder=' order by fldNameKala'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi  order by fldNameKala
else if @order=2 
	--set @StrOrder=' order by Convert(dec,SumMande) desc'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by Convert(dec,SumMande) desc
else if @order=3 
	--set @StrOrder=' order by Convert(dec,SumMande) asc'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi  order by Convert(dec,SumMande) asc
else if @order=4 
	--set @StrOrder=' order by fldKharid desc'	
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by fldKharid desc
else if @order=5 
	--set @StrOrder=' order by fldKharid asc'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by fldKharid asc
else if @Order=6
	--set @StrOrder=' order by fldGroupName desc'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by fldGroupName desc
else if @Order=7
	--set @StrOrder=' order by fldCodeGroup asc'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by fldCodeGroup asc


end
GO

-- ===============================================
-- SP: [dbo].[ShowListMojoodieAnbarAll]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListMojoodieAnbarAll', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListMojoodieAnbarAll] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListMojoodieAnbarAll]

  @MiangineKharid  nvarchar(20) output,
  @JameTedad bigint output,
  @Order int,
  @Filter int
--@nn nvarchar(10)

as

begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
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) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20) COLLATE Persian_100_CI_AS
)


create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 0),
SumKhorooj decimal(18, 0),
SumMande decimal(18, 0),
fldTedadDarKarton decimal(18, 0),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadVoroodKarton decimal(18, 0),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadKhoroojKarton decimal(18, 0),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh decimal(18, 0),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
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

-- ===============================================
-- SP: [dbo].[ShowListMojoodieAnbarDateEngheza]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListMojoodieAnbarDateEngheza', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListMojoodieAnbarDateEngheza] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListMojoodieAnbarDateEngheza]
  @userCode bigint,
  @MiangineKharid bigint output,
  @JameTedad bigint output,
  @lngSumTedadeKolSahih bigint output,
  @Order int,
  @Filter int,
  @ListCodeKala varchar(5000)=null,
  @ListCodeAnbar varchar(5000)=null,
  @ListGroupKala varchar(5000)=null,
  @DateTa bigint,
  @NoeFeeKharid int
--@nn nvarchar(10)

as

IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
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) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20) COLLATE Persian_100_CI_AS,
fldDateEngheza bigint
)


create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 0),
SumKhorooj decimal(18, 0),
SumMande decimal(18, 0),
fldTedadDarKarton decimal(18, 0),
fldTedadKartonadadSahih decimal(18, 0),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadVoroodKarton decimal(18, 0),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadKhoroojKarton decimal(18, 0),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh decimal(18, 0),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldKharid bigint,
fldArzesheMojoodi bigint,
fldFeeForoosh bigint,
fldDateEngheza bigint
)



INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType,fldDateEngheza)
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,fldDateEngheza
FROM            tblRizeKharid Where flddate<=@DateTa


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' ,fldTedadJozNahaei, 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            tblRizeTolid where fldType='mahsool' and flddate<=@DateTa



INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType,fldDateEngheza)
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,fldDateEngheza
FROM            tblRizeBargashtAzForoosh Where flddate<=@DateTa


INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType,fldDateEngheza)
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,fldDateEngheza
FROM            tblRizeForoosh Where flddate<=@DateTa


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,fldTedadJozAvalie , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeTolid where fldType='avalie' and flddate<=@DateTa


INSERT INTO #TempMojoodieAnbar
                         (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
                         fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType,fldDateEngheza)
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,fldDateEngheza
FROM            tblRizeBargashtAzKharid Where flddate<=@DateTa


update #TempMojoodieAnbar set fldFeeForoosh=tblKala.fldFeeForoosh from tblKala Where #TempMojoodieAnbar.fldCodeKala=tblKala.fldCodeKala


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 fldDateEngheza=0 Where fldDateEngheza is Null

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,fldFeeForoosh,fldDateEngheza)
SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
                         fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0,fldFeeForoosh,fldDateEngheza
FROM            #TempMojoodieAnbar
GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh,fldDateEngheza





--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 @NoeFeeKharid=1 --میانگین خرید
	update #TempShowMojoodi set fldKharid=tbl1.Miangin from
	(SELECT        ROUND(SUM(fldFeeKol) / SUM(fldTedadJoz), 0) AS Miangin, fldCodeKala
	FROM            tblRizeKharid
	GROUP BY fldCodeKala
	having         SUM(fldTedadJoz)>0
	) as tbl1
	where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala 
else --آخرین فی خرید
	begin
	--update #TempShowMojoodi set fldKharid=ROUND((tblRizeKharid.fldFeeKol) / (tblRizeKharid.fldTedadJoz), 0) from
	--	tblRizeKharid where  tblRizeKharid.fldCodeKala=#TempShowMojoodi.fldCodeKala 
	
		DECLARE @t TABLE(
		UniqueID INT,
		fldCodeKala bigint,
		[Fee] decimal(18,0),
		fldDate BIGINT
		);

		insert into @t
			(fldCodeKala,[Fee],fldDate)
			Select fldCodeKala, ROUND((tblRizeKharid.fldFeeKol) / (tblRizeKharid.fldTedadJoz), 0),fldDATE from tblRizeKharid


		update #TempShowMojoodi set fldKharid=tbl1.[Fee] from 
			(SELECT t.fldCodeKala,MAX(t.[Fee]) AS [Fee],t.fldDate
			FROM @t t
			INNER JOIN(
				SELECT MAX(fldDate) AS fldDate,fldCodeKala
				FROM @t t
				GROUP BY fldCodeKala
			) AS t2
			ON t.[fldDate] = t2.[fldDate] 
				AND t.[fldCodeKala] = t2.fldCodeKala
			GROUP BY 
				t.fldCodeKala,
				t.[fldDate])as tbl1
			Where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala

	end
	



--پاک کردن گروه کالاهایی که در گزارش نیستن
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)
update #TempShowMojoodi set fldTedadKartonadadSahih=(SumMande/fldTedadDarKarton)   Where fldTedadDarKarton>0
update #TempShowMojoodi set fldTedadKartonadadSahih=0 Where isnumeric(fldTedadKartonadadSahih)=0
set @lngSumTedadeKolSahih=(Select Sum(fldTedadKartonadadSahih) from #TempShowMojoodi)


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)


 -- Delete Not accessable Kala
 
 -- Group Kala access
 Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA')
  if @value = 'True'
  Begin -- Limitation Active  
	-- Get All AccessKala
	declare @accesskala table(code bigint)
	insert into @accesskala 
	exec [ZSP_GetKalaAccesses] @userCode

	delete #TempShowMojoodi where fldCodeGroup not in (select code from @accesskala)
end

 Set @Select='Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldDateEngheza 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,fldDateEngheza'
else if @order=1 	
	set @StrOrder=' order by fldNameKala,fldDateEngheza'
else if @order=2 
	set @StrOrder=' order by SumMande desc,fldDateEngheza,fldCodeKala'
else if @order=3 
	set @StrOrder=' order by SumMande asc,fldDateEngheza'
else if @order=4 
	set @StrOrder=' order by fldKharid desc,fldDateEngheza,fldCodeKala'	
else if @order=5 
	set @StrOrder=' order by fldKharid asc,fldDateEngheza,fldCodeKala'
else if @Order=6
	set @StrOrder=' order by fldGroupName desc,fldDateEngheza,fldCodeKala'
else if @Order=7
	set @StrOrder=' order by fldCodeGroup asc,fldDateEngheza,fldCodeKala'
else if @Order=8
	set @StrOrder=' order by fldDateEngheza asc,fldCodeKala'
else if @Order=9
	set @StrOrder=' order by fldDateEngheza desc,fldCodeKala'

execute(@select + @StrOrder)

	 

end
GO

-- ===============================================
-- SP: [dbo].[ShowListMojoodieAnbarForForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListMojoodieAnbarForForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListMojoodieAnbarForForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListMojoodieAnbarForForoosh]        
--@nn nvarchar(10)
	@ShowMojoodi int

as

IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldTedadeVorood decimal(18, 2),
fldTedadeKhorooj decimal(18, 2),
fldTedadeJoz decimal(18, 2), 
fldTedadeKol decimal(18, 2), 
fldTedadDarKarton decimal(18, 2),
fldCodeAnbar int,
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 2),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20) COLLATE Persian_100_CI_AS
)


create table #TempShowMojoodi2(

fldCodeKala bigint,
SumVorood decimal(18, 2),
SumKhorooj decimal(18, 2),
SumMande decimal(18, 2),
Mande nvarchar(18),
mandeeee nvarchar(10),
fldTedadDarKarton decimal(18, 2),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadVoroodKarton decimal(18, 2),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadKhoroojKarton decimal(18, 2),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldModat int,
fldNogheSefaresh decimal(18, 2),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldKharid bigint,
fldFeeForoosh money,
fldArzesheMojoodi bigint
)

if @ShowMojoodi=1
	begin
		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
			where fldType<>'amani'


		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' ,fldTedadJozNahaei, 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            tblRizeTolid where fldType='mahsool'


		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            tblRizHavaleHazine



		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,fldTedadJozAvalie , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
								 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
		FROM            tblRizeTolid where fldType='avalie'



		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 #TempShowMojoodi2
			(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 #TempShowMojoodi2 set fldNameVahed2='' where fldTedadDarKarton=0

		update #TempShowMojoodi2 Set fldTedadDarKartonShow=Convert(varchar,floor(SumMande / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, Convert(float,{ fn MOD(SumMande, fldTedadDarKarton) }) ) + ' ' + fldNameVahed
			where fldTedadDarKarton>0

		update #TempShowMojoodi2 Set fldTedadVoroodKartonShow=Convert(varchar,floor(SumVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, Convert(float,{ fn MOD(SumVorood, fldTedadDarKarton) }) ) + ' ' + fldNameVahed
			where fldTedadDarKarton>0

		update #TempShowMojoodi2 Set fldTedadKhoroojKartonShow=Convert(varchar,floor(SumKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar,Convert(float, { fn MOD(Sumkhorooj, fldTedadDarKarton) } )) + ' ' + fldNameVahed
			where fldTedadDarKarton>0





		update #TempShowMojoodi2 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=#TempShowMojoodi2.fldCodeKala





		--محاسبه ارزش موجودی هر کالا
		update #TempShowMojoodi2 set fldArzesheMojoodi=0
		update #TempShowMojoodi2 set fldArzesheMojoodi=SumMande*fldKharid where SumMande>0



	

	

		update #TempShowMojoodi2 set fldFeeForoosh=tblKala.fldFeeForoosh from tblkala Where #TempShowMojoodi2.fldCodeKala=tblKala.fldCodeKala
		update #TempShowMojoodi2 set fldModat=tblKala.fldModat from tblkala Where #TempShowMojoodi2.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 #TempShowMojoodi2 '

		--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	 
		--update #TempShowMojoodi Set fldTedadDarKartonShow='666',SumMande=6547

		update #TempShowMojoodi2 set Mande=SumMande
		update #TempShowMojoodi2 set Mande=LEFT(Convert(varchar,SumMande),len(Convert(varchar,SumMande))-3) where right(convert(varchar,SumMande),2)='00'
	end
else
		Insert into #TempShowMojoodi2
			(fldCodeKala,fldNameKala,fldFeeForoosh,fldModat,fldNameVahed,fldNameVahed2,SumMande,fldTedadDarKarton, fldCodeGroup, fldTedadDarKartonShow)
			SELECT        dbo.tblKala.fldCodeKala , dbo.tblKala.fldNameKala,fldFeeForoosh,fldModat, dbo.tblVahed.fldNameVahed, tblVahed_1.fldNameVahed AS fldNameVahed2,0 as SumMande,0,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

select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,Mande as SumMande,fldFeeForoosh,fldmodat, fldCodeGroup,fldTedadDarKartonShow from  #TempShowMojoodi2	  Where fldNameKala<>'NameKala'

end
GO

-- ===============================================
-- SP: [dbo].[ShowListMojoodieAnbar-HavaleSefaresh]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListMojoodieAnbar-HavaleSefaresh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListMojoodieAnbar-HavaleSefaresh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListMojoodieAnbar-HavaleSefaresh]
  @userCode bigint,
  @MiangineKharid bigint output,
  @JameTedad bigint output,
  @lngSumTedadeKolSahih bigint output,
  @Order int,
  @Filter int,
  @ListCodeKala varchar(5000)=null,
  @ListCodeAnbar varchar(5000)=null,
  @ListCodeAnbarKhales ZT_CodeNumbers readonly,
  @ListGroupKala varchar(5000)=null,  
  @ListGroupKalaKhales ZT_CodeNumbers readonly,
  @DateTa bigint,
  @NoeFeeKharid int,
  @NoeAnbar nvarchar(20),
  @sefareshat  nvarchar(15)
--@nn nvarchar(10)

as

IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldTedadeVorood decimal(18, 2),
fldTedadeKhorooj decimal(18, 2),
fldTedadeJoz decimal(18, 2), 
fldTedadeKol decimal(18, 2), 
fldTedadDarKarton decimal(18, 2),
fldCodeAnbar int,
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 2),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldTedadeForoosh decimal(18, 2),
fldTedadeBargashtAzForoosh decimal(18, 2),
fldTedadeKharid decimal(18, 2),
fldTedadeBargashtAzKharid decimal(18, 2),
fldTedadeTolidVorood decimal(18, 2),
fldTedadeTolidKhorooj decimal(18, 2),
fldType nvarchar(20) COLLATE Persian_100_CI_AS
)


create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 2),
SumVoroodT nvarchar(200),
SumKhorooj decimal(18, 2),
SumKhoroojT nvarchar(200),
SumMande decimal(18, 2),
Mande nvarchar(200),
fldTedadDarKarton decimal(18, 0),
fldTedadKartonadadSahih decimal(18, 2),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadVoroodKarton decimal(18, 2),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadKhoroojKarton decimal(18, 2),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh decimal(18, 2),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldKharid bigint,
fldArzesheMojoodi bigint,
fldFeeForoosh bigint,
fldGhymatMasrafkonande dec(18,0),

fldTedadeForoosh decimal(18, 2),
fldTedadeForooshShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadeBargashtAzForoosh decimal(18, 2),
fldTedadeBargashtAzForooshShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadeKharid decimal(18, 2),
fldTedadeEnteghalVorood decimal(18, 2),
fldTedadeEnteghalKhorooj decimal(18, 2),
fldTedadeKharidShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadeBargashtAzKharid decimal(18, 2),
fldTedadeBargashtAzKharidShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadeTolidVorood decimal(18, 2),
fldTedadeTolidVoroodShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadeTolidKhorooj decimal(18, 2),
fldTedadeTolidKhoroojShow nvarchar(70) COLLATE Persian_100_CI_AS
)


declare @countGroup bigint
set @countGroup=0--( select count(CodeNumber) from @ListGroupKalaKhales)


--#####درست کردن فیلدهای ابتدای دوره
UPDATE       tblRizeKharid SET fldMablaghKhales = fldFeeKol WHERE        (fldType = 'mojodi_ebteda_doreh')

UPDATE       tblRizeKharid SET fldFeeKolBadAzTakhfif = fldFeeKol WHERE        (fldType = 'mojodi_ebteda_doreh')

update tblRizeKharid set fldFeeVahed1BadAzTakhfif=fldFeeJoz where  fldType='mojodi_ebteda_doreh'

update tblRizeKharid set fldFeeKolBadAzTakhfif=fldFeeVahed1BadAzTakhfif*fldTedadJoz where  fldType='mojodi_ebteda_doreh'
---######################################


if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeKharid, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) ) 
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeKharid, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz,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 Where flddate<=@DateTa   and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


	--else
--		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 Where flddate<=@DateTa  and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (@ListGroupKalaKhales) )

if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeTolidVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJozNahaei,fldTedadJozNahaei, 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            tblRizeTolid where fldType='mahsool' and flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeTolidVorood, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJozNahaei,fldTedadJozNahaei, 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            tblRizeTolid where fldType='mahsool' and flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeBargashtAzForoosh, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeBargashtAzForoosh, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol,fldTedadDarKarton,fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,fldTedadJoz,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,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 Where flddate<=@DateTa   and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


-- برای حالتی که سفارشات از حواله گروهی سفارشات ویزیتور میاد
--کسر گردد پیش فاکتورهایی که حواله شده و برگشت نخورده اند و فاکتور نشده اند
if @sefareshat='sefareshat'
	if @countGroup >0
		INSERT INTO #TempMojoodieAnbar
								 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
								 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
		SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,fldTedadJoz, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
								 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
		FROM            tblRizePishPishForoosh Where 
					fldShomareFactor in 
					(SELECT        fldShomareFactor
						FROM            tblHavaleGoroohi
					WHERE        (fldType ='pishfactor') and fldbargasht is NULL and fldShomareFactor not in (select fldShomarePishFactor from tblforoosh where fldShomarePishFactor is not NULL  ))
						and   flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
	else
		INSERT INTO #TempMojoodieAnbar
								 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
								 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
		SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,fldTedadJoz, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
								 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
		FROM            tblRizePishPishForoosh Where 
					fldShomareFactor in 
					(SELECT        fldShomareFactor
						FROM            tblHavaleGoroohi
					WHERE        (fldType ='pishfactor') and fldbargasht is NULL and fldShomareFactor not in (select fldShomarePishFactor from tblforoosh where fldShomarePishFactor is not NULL  ))
					And flddate<=@DateTa   and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)



if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,fldTedadJoz, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
							 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
	FROM            tblRizHavaleHazine Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales) and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeForoosh, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,fldTedadJoz, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
							 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
	FROM            tblRizHavaleHazine Where flddate<=@DateTa   and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeTolidKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJozAvalie ,fldTedadJozAvalie, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
							 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
	FROM            tblRizeTolid where fldType='avalie' and flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)   and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood, fldTedadeKhorooj,fldTedadeTolidKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJozAvalie ,fldTedadJozAvalie, - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
							 0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
	FROM            tblRizeTolid where fldType='avalie' and flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


if @countGroup >0
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeBargashtAzKharid, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)  and fldCodeKala in (select fldcodekala from tblKala where fldCodeGroup in (select CodeNumber from @ListGroupKalaKhales) )
else
	INSERT INTO #TempMojoodieAnbar
							 (fldGroupName,fldCodeGroup, fldCodeKala, fldNameKala,fldTedadeVorood,fldTedadeBargashtAzKharid, fldTedadeKhorooj, fldTedadeJoz, fldTedadeKol, fldCodeAnbar, fldNameAnbar, fldNogheSefaresh, fldFeeForoosh, 
							 fldLastFee, fldMianginFee, fldNameVahed, fldNameVahed2,fldDate,fldType)
	SELECT        'NameGroup',- 1 , fldCodeKala, 'NameKala' ,0,fldTedadJoz ,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 Where flddate<=@DateTa  and fldCodeAnbar in (Select CodeNumber  from @ListCodeAnbarKhales)


update #TempMojoodieAnbar set fldFeeForoosh=tblKala.fldFeeForoosh from tblKala Where #TempMojoodieAnbar.fldCodeKala=tblKala.fldCodeKala

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)



if @NoeAnbar='amani'
	delete #TempMojoodieAnbar where fldCodeAnbar<2000
else
	delete #TempMojoodieAnbar where fldCodeAnbar>=2000


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


--فیلتر تا قبل از تاریخ 

update #TempShowMojoodi set fldTedadeForoosh=0 where fldTedadeForoosh is Null
update #TempShowMojoodi set fldTedadeBargashtAzForoosh=0 where fldTedadeBargashtAzForoosh is Null
update #TempShowMojoodi set fldTedadeBargashtAzForoosh=0 where fldTedadeBargashtAzForoosh is Null
update #TempShowMojoodi set fldTedadeKharid=0 where fldTedadeKharid is Null
update #TempShowMojoodi set fldTedadeBargashtAzKharid=0 where fldTedadeBargashtAzKharid is Null
update #TempShowMojoodi set fldTedadeTolidVorood=0 where fldTedadeTolidVorood is Null
update #TempShowMojoodi set fldTedadeTolidKhorooj=0 where fldTedadeTolidKhorooj is Null
update #TempShowMojoodi set fldTedadeForoosh=0 where fldTedadeForoosh is Null


if @Filter=5
	begin
		Insert into #TempShowMojoodi
				(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid,fldFeeForoosh,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj)
			SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, 0 AS SumTedadeKhorooj, SUM(fldTedadeVorood ) AS sumMande, 
									 fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0,fldFeeForoosh ,sum(fldTedadeForoosh),sum(fldTedadeBargashtAzForoosh),sum(fldTedadeKharid),sum(fldTedadeBargashtAzKharid),sum(fldTedadeTolidVorood),sum(fldTedadeTolidKhorooj)
			FROM            #TempMojoodieAnbar where fldType='enteghal'
			GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh--,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj
	end
else
	begin
		Insert into #TempShowMojoodi
			(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid,fldFeeForoosh,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj)
		SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
								 fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0,fldFeeForoosh,sum(fldTedadeForoosh),sum(fldTedadeBargashtAzForoosh),sum(fldTedadeKharid),sum(fldTedadeBargashtAzKharid),sum(fldTedadeTolidVorood),sum(fldTedadeTolidKhorooj)
		FROM            #TempMojoodieAnbar
		GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh--,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj

		update #TempShowMojoodi set fldTedadeKharid = tbl1.sumtedad from (select sum(tblrizekharid.fldTedadJoz) as sumTedad,fldcodekala from tblRizeKharid where fldtype='Kharid' group by fldCodeKala) as tbl1
				where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala


--declare @StrUpdateAnbar varchar(5000), @enteghal varchar(5000)
--					set @enteghal='enteghal'
--					set @StrUpdateAnbar='select sum(tblrizekharid.fldTedadJoz) as sumTedad,fldcodekala from tblRizeKharid where fldtype ='''+ @enteghal +'''  group by fldCodeKala'
--					execute(@StrUpdateAnbar)

		if @ListCodeAnbar <>''
		     begin
		      declare @StrUpdateAnbar varchar(5000)
		       set  @StrUpdateAnbar='update #TempMojoodieAnbar 
		            where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
					execute(@StrDeleteAnbar)
					
					set @StrUpdateAnbar='update #TempShowMojoodi set fldTedadeEnteghalKhorooj= tbl1.sumtedad from (select sum(tblrizekharid.fldTedadJoz) as sumTedad,fldcodekala from tblRizeKharid where fldtype=''enteghal'' and fldCodeAnbar NOT IN ('+ @ListCodeAnbar +') group by fldCodeKala ) as tbl1
									where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala'
					execute(@StrUpdateAnbar)

					set @StrUpdateAnbar='update #TempShowMojoodi set fldTedadeEnteghalVorood  = tbl1.sumtedad from (select sum(tblRizeForoosh.fldTedadJoz) as sumTedad,fldcodekala from tblRizeForoosh where fldtype=''enteghal'' and fldCodeAnbar NOT IN ('+ @ListCodeAnbar +') group by fldCodeKala ) as tbl1
									where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala'
					execute(@StrUpdateAnbar)

					set @StrUpdateAnbar='update #TempShowMojoodi set fldTedadeForoosh= tbl1.sumtedad from (select sum(tblRizeForoosh.fldTedadJoz) as sumTedad,fldcodekala from tblRizeForoosh where fldtype=''Foroosh'' and fldCodeAnbar  IN ('+ @ListCodeAnbar +') group by fldCodeKala ) as tbl1
									where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala'
					--set @StrUpdateAnbar='update #TempShowMojoodi set fldTedadeForoosh= 555'
									
					execute(@StrUpdateAnbar)

			 end
		else
			begin
					update #TempShowMojoodi set fldTedadeEnteghalKhorooj  = tbl1.sumtedad from (select sum(tblrizekharid.fldTedadJoz) as sumTedad,fldcodekala from tblRizeKharid where fldtype='enteghal' group by fldCodeKala) as tbl1
							where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala

					update #TempShowMojoodi set fldTedadeEnteghalVorood= tbl1.sumtedad from (select sum(tblRizeForoosh.fldTedadJoz) as sumTedad,fldcodekala from tblRizeForoosh where fldtype='enteghal' group by fldCodeKala) as tbl1
							where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala

					update #TempShowMojoodi set fldTedadeForoosh= tbl1.sumtedad from (select sum(tblRizeForoosh.fldTedadJoz) as sumTedad,fldcodekala from tblRizeForoosh where fldtype='Foroosh' group by fldCodeKala ) as tbl1
							where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala
			end
	end


update #TempShowMojoodi set Mande=SumMande,SumVoroodT=SumVorood,SumKhoroojT=SumKhorooj
update #TempShowMojoodi set Mande=LEFT(Convert(varchar,SumMande),len(Convert(varchar,SumMande))-3) where right(convert(varchar,SumMande),2)='00'
update #TempShowMojoodi set SumVoroodT=LEFT(Convert(varchar,SumVorood),len(Convert(varchar,SumVorood))-3) where right(convert(varchar,SumVorood),2)='00'
update #TempShowMojoodi set SumKhoroojT=LEFT(Convert(varchar,SumKhorooj),len(Convert(varchar,SumKhorooj))-3) where right(convert(varchar,SumKhorooj),2)='00'

--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(Convert(dec, SumMande), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadVoroodKartonShow=Convert(varchar,floor(SumVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,SumVorood), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadKhoroojKartonShow=Convert(varchar,floor(SumKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,Sumkhorooj), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0


update #TempShowMojoodi Set fldTedadDarKartonShow=Convert(varchar,floor(SumMande / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec, SumMande), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0


--update #TempShowMojoodi Set fldTedadeForooshShow=Convert(varchar,floor(SumMande / fldTedadeForoosh)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec, SumMande), fldTedadDarKarton) } ) + ' ' + fldNameVahed
--	where fldTedadDarKarton>0




--fldTedadeBargashtAzForooshShow
--fldTedadeKharidShow

--fldTedadeBargashtAzKharidShow

--fldTedadeTolidVoroodShow

--fldTedadeTolidKhoroojShow



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 @NoeFeeKharid=1 --میانگین خرید
	begin
		update #TempShowMojoodi set fldKharid=tbl1.Miangin from
		(SELECT        ROUND(SUM(fldFeeKolBadAzTakhfif) / SUM(fldTedadJoz), 0) AS Miangin, fldCodeKala
		FROM            tblRizeKharid
		where fldType<>'enteghal' and fldDate <= @DateTa 
		GROUP BY fldCodeKala
		having         SUM(fldTedadJoz)>0 
		) as tbl1
		where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala  


		update #TempShowMojoodi set fldKharid=tbl1.Miangin from
			(SELECT        ROUND(SUM(fldFeeKol) / SUM(fldTedadJozNahaei), 0) AS Miangin, fldCodeKala
			FROM            tblRizeTolid
			where fldType<>'enteghal' and fldDate <= @DateTa 
			GROUP BY fldCodeKala
			having         SUM(fldTedadJozNahaei)>0 
			) as tbl1
			where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala  
		end
else if @NoeFeeKharid=2 --آخرین فی خرید
	begin
	--update #TempShowMojoodi set fldKharid=ROUND((tblRizeKharid.fldFeeKol) / (tblRizeKharid.fldTedadJoz), 0) from
	--	tblRizeKharid where  tblRizeKharid.fldCodeKala=#TempShowMojoodi.fldCodeKala 
	
		DECLARE @t TABLE(
		UniqueID INT,
		fldCodeKala bigint,
		[Fee] decimal(18,0),
		fldDate BIGINT
		);

		insert into @t
			(fldCodeKala,[Fee],fldDate)
			Select fldCodeKala, ROUND((tblRizeKharid.fldFeeKolBadAzTakhfif) / (tblRizeKharid.fldTedadJoz), 0),fldDATE from tblRizeKharid where fldType<>'enteghal' and tblRizeKharid.fldTedadJoz>0 and fldDate <= @DateTa 


		update #TempShowMojoodi set fldKharid=tbl1.[Fee] from 
			(SELECT t.fldCodeKala,MAX(t.[Fee]) AS [Fee],t.fldDate
			FROM @t t
			INNER JOIN(
				SELECT MAX(fldDate) AS fldDate,fldCodeKala
				FROM @t t
				GROUP BY fldCodeKala
			) AS t2
			ON t.[fldDate] = t2.[fldDate] 
				AND t.[fldCodeKala] = t2.fldCodeKala
			GROUP BY 
				t.fldCodeKala,
				t.[fldDate])as tbl1
			Where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala




		insert into @t
			(fldCodeKala,[Fee],fldDate)
			Select fldCodeKala, ROUND((tblRizeTolid.fldFeeKol) / (tblRizeTolid.fldTedadJozNahaei), 0),fldDATE from tblRizeTolid where fldType<>'enteghal' and tblRizeTolid.fldTedadJozNahaei>0 and fldDate <= @DateTa 


		update #TempShowMojoodi set fldKharid=tbl1.[Fee] from 
			(SELECT t.fldCodeKala,MAX(t.[Fee]) AS [Fee],t.fldDate
			FROM @t t
			INNER JOIN(
				SELECT MAX(fldDate) AS fldDate,fldCodeKala
				FROM @t t
				GROUP BY fldCodeKala
			) AS t2
			ON t.[fldDate] = t2.[fldDate] 
				AND t.[fldCodeKala] = t2.fldCodeKala
			GROUP BY 
				t.fldCodeKala,
				t.[fldDate])as tbl1
			Where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala

	end

else if @NoeFeeKharid=3 --في فروش
	begin
		update #TempShowMojoodi set fldKharid=fldFeeForoosh
	end
	



--پاک کردن گروه کالاهایی که در گزارش نیستن
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

----انتقال کالا
--if @Filter=4
--		delete from #TempShowMojoodi Where  fldtype<>'enteghal'




			--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)


  delete #TempShowMojoodi where fldNameKala='NameKala'
  
  -- Group Kala access
 Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA')
  if @value = 'True'
  Begin -- Limitation Active  
	-- Get All AccessKala
	declare @accesskala table(code bigint)
	insert into @accesskala 
	exec [ZSP_GetKalaAccesses] @userCode

	delete #TempShowMojoodi where fldCodeGroup not in (select code from @accesskala)
end

 Set @Select='Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi'

--Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	--fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid ,@strorder
	--from #TempShowMojoodi


--محاسبه ارزش موجودی هر کالا
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

	

	


update #TempShowMojoodi set fldTedadKartonadadSahih=(SumMande/fldTedadDarKarton)   Where fldTedadDarKarton>0
update #TempShowMojoodi set fldTedadKartonadadSahih=0 Where isnumeric(fldTedadKartonadadSahih)=0
set @lngSumTedadeKolSahih=(Select Sum(fldTedadKartonadadSahih) from #TempShowMojoodi)

update #TempShowMojoodi set fldGhymatMasrafkonande=tblKala.fldGhymatMasrafkonande from tblKala where tblKala.fldCodeKala=#TempShowMojoodi.fldCodeKala


update #TempShowMojoodi Set fldTedadDarKartonShow=convert(varchar,(-1)*Convert(varchar,floor((-1)*convert(dec,Mande) / convert(dec,fldTedadDarKarton)))) + ' کل ' +  Convert(varchar, { fn MOD(Convert(dec, Mande), convert(dec,fldTedadDarKarton)) } )  +  ' جز '
where convert(dec,Mande)<0 and fldTedadDarKarton>0

Set @JameTedad=(Select Sum(SumMande)  from #TempShowMojoodi Where SumMande>0)
if   @JameTedad is null
	set @JameTedad=0

if @Order=0 
	--set @StrOrder=' order by fldCodeKala'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by fldCodeKala
else if @order=1 	
	--set @StrOrder=' order by fldNameKala'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi  order by fldNameKala
else if @order=2 
	--set @StrOrder=' order by Convert(dec,SumMande) desc'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by Convert(dec,SumMande) desc
else if @order=3 
	--set @StrOrder=' order by Convert(dec,SumMande) asc'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi  order by Convert(dec,SumMande) asc
else if @order=4 
	--set @StrOrder=' order by fldKharid desc'	
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by fldKharid desc
else if @order=5 
	--set @StrOrder=' order by fldKharid asc'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by fldKharid asc
else if @Order=6
	--set @StrOrder=' order by fldGroupName desc'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by fldGroupName desc
else if @Order=7
	--set @StrOrder=' order by fldCodeGroup asc'
	Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
		fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldGhymatMasrafkonande,fldTedadeForoosh,fldTedadeBargashtAzForoosh,fldTedadeKharid,fldTedadeEnteghalVorood,fldTedadeEnteghalKhorooj,fldTedadeBargashtAzKharid,fldTedadeTolidVorood,fldTedadeTolidKhorooj from #TempShowMojoodi order by fldCodeGroup asc


end
GO

-- ===============================================
-- SP: [dbo].[ShowListMojoodieAnbar-TypeOld]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListMojoodieAnbar-TypeOld', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListMojoodieAnbar-TypeOld] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListMojoodieAnbar-TypeOld]
  @userCode bigint,
  @MiangineKharid bigint output,
  @JameTedad bigint output,
  @lngSumTedadeKolSahih bigint output,
  @Order int,
  @Filter int,
  @ListCodeKala varchar(5000)=null,
  @ListCodeAnbar varchar(5000)=null,
  @ListGroupKala varchar(5000)=null,
  @DateTa bigint,
  @NoeFeeKharid int,
  @NoeAnbar nvarchar(20)
--@nn nvarchar(10)

as

IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldTedadeVorood decimal(18, 2),
fldTedadeKhorooj decimal(18, 2),
fldTedadeJoz decimal(18, 2), 
fldTedadeKol decimal(18, 2), 
fldTedadDarKarton decimal(18, 2),
fldCodeAnbar int,
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 2),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20) COLLATE Persian_100_CI_AS
)


create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 2),
SumVoroodT nvarchar(200),
SumKhorooj decimal(18, 2),
SumKhoroojT nvarchar(200),
SumMande decimal(18, 2),
Mande nvarchar(200),
fldTedadDarKarton decimal(18, 0),
fldTedadKartonadadSahih decimal(18, 2),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadVoroodKarton decimal(18, 2),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadKhoroojKarton decimal(18, 2),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh decimal(18, 2),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldKharid bigint,
fldArzesheMojoodi bigint,
fldFeeForoosh 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 Where flddate<=@DateTa


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' ,fldTedadJozNahaei, 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            tblRizeTolid where fldType='mahsool' and flddate<=@DateTa



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 Where flddate<=@DateTa


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 Where flddate<=@DateTa


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,fldTedadJozAvalie , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeTolid where fldType='avalie' and flddate<=@DateTa


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 Where flddate<=@DateTa


update #TempMojoodieAnbar set fldFeeForoosh=tblKala.fldFeeForoosh from tblKala Where #TempMojoodieAnbar.fldCodeKala=tblKala.fldCodeKala

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)



if @NoeAnbar='amani'
	delete #TempMojoodieAnbar where fldCodeAnbar<2000
else
	delete #TempMojoodieAnbar where fldCodeAnbar>=2000


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,fldFeeForoosh)
SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
                         fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0,fldFeeForoosh
FROM            #TempMojoodieAnbar
GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh



update #TempShowMojoodi set Mande=SumMande,SumVoroodT=SumVorood,SumKhoroojT=SumKhorooj
update #TempShowMojoodi set Mande=LEFT(Convert(varchar,SumMande),len(Convert(varchar,SumMande))-3) where right(convert(varchar,SumMande),2)='00'
update #TempShowMojoodi set SumVoroodT=LEFT(Convert(varchar,SumVorood),len(Convert(varchar,SumVorood))-3) where right(convert(varchar,SumVorood),2)='00'
update #TempShowMojoodi set SumKhoroojT=LEFT(Convert(varchar,SumKhorooj),len(Convert(varchar,SumKhorooj))-3) where right(convert(varchar,SumKhorooj),2)='00'

--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(Convert(dec, SumMande), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadVoroodKartonShow=Convert(varchar,floor(SumVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,SumVorood), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadKhoroojKartonShow=Convert(varchar,floor(SumKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,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 @NoeFeeKharid=1 --میانگین خرید
	update #TempShowMojoodi set fldKharid=tbl1.Miangin from
	(SELECT        ROUND(SUM(fldFeeKolBadAzTakhfif) / SUM(fldTedadJoz), 0) AS Miangin, fldCodeKala
	FROM            tblRizeKharid
	where fldType<>'enteghal' and tblRizeKharid.fldTedadJoz>0 and fldFeeJoz>0
	GROUP BY fldCodeKala
	having         SUM(fldTedadJoz)>0 
	) as tbl1
	where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala  
else if @NoeFeeKharid=2 --آخرین فی خرید
	begin
	--update #TempShowMojoodi set fldKharid=ROUND((tblRizeKharid.fldFeeKol) / (tblRizeKharid.fldTedadJoz), 0) from
	--	tblRizeKharid where  tblRizeKharid.fldCodeKala=#TempShowMojoodi.fldCodeKala 
	
		DECLARE @t TABLE(
		UniqueID INT,
		fldCodeKala bigint,
		[Fee] decimal(18,0),
		fldDate BIGINT
		);

		insert into @t
			(fldCodeKala,[Fee],fldDate)
			Select fldCodeKala, ROUND((tblRizeKharid.fldFeeKolBadAzTakhfif) / (tblRizeKharid.fldTedadJoz), 0),fldDATE from tblRizeKharid where fldType<>'enteghal' and tblRizeKharid.fldTedadJoz>0 and fldFeeJoz>0


		update #TempShowMojoodi set fldKharid=tbl1.[Fee] from 
			(SELECT t.fldCodeKala,MAX(t.[Fee]) AS [Fee],t.fldDate
			FROM @t t
			INNER JOIN(
				SELECT MAX(fldDate) AS fldDate,fldCodeKala
				FROM @t t
				GROUP BY fldCodeKala
			) AS t2
			ON t.[fldDate] = t2.[fldDate] 
				AND t.[fldCodeKala] = t2.fldCodeKala
			GROUP BY 
				t.fldCodeKala,
				t.[fldDate])as tbl1
			Where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala

	end

else if @NoeFeeKharid=3 --في فروش
	begin
		update #TempShowMojoodi set fldKharid=fldFeeForoosh
	end
	



--پاک کردن گروه کالاهایی که در گزارش نیستن
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




			--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)


  delete #TempShowMojoodi where fldNameKala='NameKala'
  
  -- Group Kala access
 Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA')
  if @value = 'True'
  Begin -- Limitation Active  
	-- Get All AccessKala
	declare @accesskala table(code bigint)
	insert into @accesskala 
	exec [ZSP_GetKalaAccesses] @userCode

	delete #TempShowMojoodi where fldCodeGroup not in (select code from @accesskala)
end

 Set @Select='Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh from #TempShowMojoodi'

--Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	--fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid ,@strorder
	--from #TempShowMojoodi


--محاسبه ارزش موجودی هر کالا
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

	

	


update #TempShowMojoodi set fldTedadKartonadadSahih=(SumMande/fldTedadDarKarton)   Where fldTedadDarKarton>0
update #TempShowMojoodi set fldTedadKartonadadSahih=0 Where isnumeric(fldTedadKartonadadSahih)=0
set @lngSumTedadeKolSahih=(Select Sum(fldTedadKartonadadSahih) from #TempShowMojoodi)


Set @JameTedad=(Select Sum(SumMande)  from #TempShowMojoodi Where SumMande>0)
if   @JameTedad is null
	set @JameTedad=0

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 Convert(dec,SumMande) desc'
else if @order=3 
	set @StrOrder=' order by Convert(dec,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

-- ===============================================
-- SP: [dbo].[ShowListTbl_Tafsili_in_Form_Enteghal_Kala]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListTbl_Tafsili_in_Form_Enteghal_Kala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListTbl_Tafsili_in_Form_Enteghal_Kala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListTbl_Tafsili_in_Form_Enteghal_Kala]
as
begin
SELECT DISTINCT fldCodeTafzili, fldSharheTafzili
                
				
FROM            dbo.tblTafzili

end
GO

-- ===============================================
-- SP: [dbo].[ShowListTbl_Tafsili_in_FormAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListTbl_Tafsili_in_FormAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListTbl_Tafsili_in_FormAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[ShowListTbl_Tafsili_in_FormAshkhas_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListTbl_Tafsili_in_FormAshkhas_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListTbl_Tafsili_in_FormAshkhas_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListTbl_Tafsili_in_FormAshkhas_WithUserCode]
@userCode bigint
as
begin

-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################

SELECT DISTINCT fldCodeTafzili, fldCodeGroup, fldCodeGroup2,fldSharheTafzili, fldAddress,fldBlackList,
                fldCity,fldCodeEghtesadi,flddescription, fldCodeMeli,fldCodePosti,fldDate1,fldDate2,
                fldPic,fldOstan,fldShomareHesab,fldShomareSabt,
				fldVisitor,fldSharhBlackList,fldSaghfeEtebar,fldHaghighi,fldNoeSooratMoadian,fldName,fldShobe,fldCodeNaghsh
				
FROM            dbo.tblTafzili
where 
-- ##################### Group Ashkhas Limitation
fldCodeTafzili in (select code from @accessCodes) and
fldcodeNoe='1'
order by fldCodeTafzili

end
GO

-- ===============================================
-- SP: [dbo].[ShowListtblDaftarcheTell_Has_CodeTafisili]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListtblDaftarcheTell_Has_CodeTafisili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListtblDaftarcheTell_Has_CodeTafisili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListtblDaftarcheTell_Has_CodeTafisili]
@codeTafsili nvarchar(10)
as
begin

select fldIdDaftarche,fldCodeTafzili,fldName,fldShomare,fldSms,fldSharh   from tblDaftarcheTell 
where fldCodeTafzili=@codeTafsili
end
GO

-- ===============================================
-- SP: [dbo].[ShowListtblDaftarcheTell_NotHas_CodeTafisili]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowListtblDaftarcheTell_NotHas_CodeTafisili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowListtblDaftarcheTell_NotHas_CodeTafisili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowListtblDaftarcheTell_NotHas_CodeTafisili]

as
begin

select fldIdDaftarche,fldCodeTafzili,fldName,fldShomare,fldSms,fldSharh   from tblDaftarcheTell 

end
GO

-- ===============================================
-- SP: [dbo].[ShowMoadian]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowMoadian', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowMoadian] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowMoadian]

@Vaziat int,
@DateAz int,
@DateTa int,
@Asli int
--@mmm nvarchar(30),
--@IDOutPut int outPut
as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin
create table #TempShow(

ID bigint,
fldRadif bigint,
fldShomareFactor bigint,
fldCodeTafsili nvarchar(100) COLLATE Persian_100_CI_AS,
fldSharheTafzili nvarchar(250) COLLATE Persian_100_CI_AS,
fldCodeKala bigint,
fldShenaseKala nvarchar(50) COLLATE Persian_100_CI_AS,
fldNameKala nvarchar(250) COLLATE Persian_100_CI_AS,
fldTedadJoz decimal(18, 2), 
fldFeeJoz decimal(18, 0), 
fldFeeKol decimal(18, 0),  
fldMablaghTakhfif decimal(18, 0),
fldFeeVahed1BadAzTakhfif decimal(18, 0),
fldArzeshAfzode decimal(18, 0),
fldDarsadArzeshAfzoode int,
fldFeeKolBadAzTakhfif decimal(18, 0),
fldMablaghKhales decimal(18, 0),
fldMablagheNesia  decimal(18, 0),
fldDate bigint,
fldShomareEghtesadi nvarchar(50)COLLATE Persian_100_CI_AS,
fldType nvarchar(15)COLLATE Persian_100_CI_AS,
fldRefrenceMoadian nvarchar(100)COLLATE Persian_100_CI_AS,
fldTaeidMoadian int,
fldShenaseMaliatiFactor nvarchar(25)COLLATE Persian_100_CI_AS,
fldEshantion nvarchar(13) COLLATE Persian_100_CI_AS,
fldDateSarResid bigint

)

	insert into #TempShow
				(ID,fldRadif, fldShomareFactor, fldCodeTafsili, fldCodeKala, fldTedadJoz, fldFeeJoz, fldFeeKol, fldMablaghTakhfif, fldFeeVahed1BadAzTakhfif, fldArzeshAfzode,fldDarsadArzeshAfzoode, fldFeeKolBadAzTakhfif, 
											 fldMablaghKhales, fldDate,fldType,fldEshantion) 
					SELECT        ID,fldRadif, fldShomareFactor, fldCodeTafsili, fldCodeKala, fldTedadJoz, fldFeeJoz, fldFeeKol, fldMablaghTakhfif, fldFeeVahed1BadAzTakhfif, fldArzeshAfzode,fldDarsadArzeshAfzoode, fldFeeKolBadAzTakhfif, 
											 fldMablaghKhales, fldDate,fldType,fldEshantion
					FROM            tblRizeForoosh where flddate between @dateaz and @dateta  and fldtype='Foroosh'

	
			
	
--  -1 تایید نشده	
--   0 ارسال نشده
--   1 تایید شده
--   2 ارسالی وضعیت نامشخص
--   3 همه

	update #TempShow set fldShomareEghtesadi=tblTafzili.fldCodeEghtesadi  COLLATE Persian_100_CI_AS  from tblTafzili where #TempShow.fldCodeTafsili  COLLATE Persian_100_CI_AS =tblTafzili.fldCodeTafzili  COLLATE Persian_100_CI_AS 


	update #TempShow set fldSharheTafzili=tblTafzili.fldSharheTafzili  COLLATE Persian_100_CI_AS  from tblTafzili where #TempShow.fldCodeTafsili  COLLATE Persian_100_CI_AS =tblTafzili.fldCodeTafzili  COLLATE Persian_100_CI_AS 

	update #TempShow set fldNameKala=tblKala.fldNameKala from tblKala where #TempShow.fldCodeKala=tblKala.fldCodeKala

	update #TempShow set fldShenaseKala=tblKala.fldShenase from tblKala where #TempShow.fldCodeKala=tblKala.fldCodeKala

	if @asli=1
		update #TempShow set #TempShow.fldRefrenceMoadian=tblForoosh.fldRefrenceMoadianAsli,#TempShow.fldShenaseMaliatiFactor=tblForoosh.fldShenaseMaliatiFactor ,#TempShow.fldTaeidMoadian=tblForoosh.fldTaeidMoadianAsli from tblforoosh where fldShomareFactor=tblForoosh.fldShomareFactorForoosh 
	else
		update #TempShow set #TempShow.fldRefrenceMoadian=tblForoosh.fldRefrenceMoadian,#TempShow.fldShenaseMaliatiFactor=tblForoosh.fldShenaseMaliatiFactor ,#TempShow.fldTaeidMoadian=tblForoosh.fldTaeidMoadian from tblforoosh where fldShomareFactor=tblForoosh.fldShomareFactorForoosh 

	update #TempShow set fldDateSarresid =0
	update #TempShow set fldDateSarResid=tblSarResidMoadian.fldDate from tblSarResidMoadian where #TempShow.fldShomareFactor=tblSarResidMoadian.fldShomareFactor

	update #TempShow set fldMablagheNesia=tbltasfie.fldMablagheMandeFactor from tblTasfie where #TempShow.fldShomareFactor=tblTasfie.fldShomareFactor 

	--case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=0 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده'
	if @Vaziat=3		--همه
		select ID ,fldRadif ,fldShomareFactor ,fldCodeTafsili ,fldSharheTafzili ,fldCodeKala ,fldShenaseKala ,fldNameKala ,fldTedadJoz ,fldFeeJoz ,fldFeeKol, fldMablaghTakhfif,
			   fldFeeVahed1BadAzTakhfif,fldArzeshAfzode,fldDarsadArzeshAfzoode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldMablagheNesia,fldDate,fldShomareEghtesadi,fldType,fldRefrenceMoadian,fldTaeidMoadian,case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=2 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده' end as vaziatTaeid,fldShenaseMaliatiFactor,fldEshantion,fldDateSarResid
				from #TempShow order by fldShomareFactor,fldRadif
	else if @Vaziat=-0 --ارسال نشده
		select ID ,fldRadif ,fldShomareFactor ,fldCodeTafsili ,fldSharheTafzili ,fldCodeKala ,fldShenaseKala ,fldNameKala ,fldTedadJoz ,fldFeeJoz ,fldFeeKol, fldMablaghTakhfif,
			   fldFeeVahed1BadAzTakhfif,fldArzeshAfzode,fldDarsadArzeshAfzoode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldMablagheNesia,fldDate,fldShomareEghtesadi,fldType,fldRefrenceMoadian,fldTaeidMoadian,case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=2 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده' end as vaziatTaeid,fldShenaseMaliatiFactor,fldEshantion,fldDateSarResid
				from #TempShow where fldTaeidMoadian is NULL order by fldShomareFactor,fldRadif 
	else
		select ID ,fldRadif ,fldShomareFactor ,fldCodeTafsili ,fldSharheTafzili ,fldCodeKala ,fldShenaseKala ,fldNameKala ,fldTedadJoz ,fldFeeJoz ,fldFeeKol, fldMablaghTakhfif,
			   fldFeeVahed1BadAzTakhfif,fldArzeshAfzode,fldDarsadArzeshAfzoode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldMablagheNesia,fldDate,fldShomareEghtesadi,fldType,fldRefrenceMoadian,fldTaeidMoadian,case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=2 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده' end as vaziatTaeid,fldShenaseMaliatiFactor,fldEshantion,fldDateSarResid
				from #TempShow where fldTaeidMoadian =@Vaziat order by fldShomareFactor,fldRadif  
end
GO

-- ===============================================
-- SP: [dbo].[ShowMoadianAsli]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowMoadianAsli', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowMoadianAsli] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowMoadianAsli]

@Vaziat int,
@DateAz int,
@DateTa int
--@mmm nvarchar(30),
--@IDOutPut int outPut
as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin
create table #TempShow(

ID bigint,
fldRadif bigint,
fldShomareFactor bigint,
fldCodeTafsili nvarchar(100) COLLATE Persian_100_CI_AS,
fldSharheTafzili nvarchar(250) COLLATE Persian_100_CI_AS,
fldCodeKala bigint,
fldShenaseKala nvarchar(50),
fldNameKala nvarchar(250) COLLATE Persian_100_CI_AS,
fldTedadJoz decimal(18, 2), 
fldFeeJoz decimal(18, 0), 
fldFeeKol decimal(18, 0),  
fldMablaghTakhfif decimal(18, 0),
fldFeeVahed1BadAzTakhfif decimal(18, 0),
fldArzeshAfzode decimal(18, 0),
fldFeeKolBadAzTakhfif decimal(18, 0),
fldMablaghKhales decimal(18, 0),
fldDate bigint,
fldShomareEghtesadi nvarchar(50),
fldRefrenceMoadian nvarchar(100),
fldTaeidMoadian int

)

	insert into #TempShow
				(ID,fldRadif, fldShomareFactor, fldCodeTafsili, fldCodeKala, fldTedadJoz, fldFeeJoz, fldFeeKol, fldMablaghTakhfif, fldFeeVahed1BadAzTakhfif, fldArzeshAfzode, fldFeeKolBadAzTakhfif, 
											 fldMablaghKhales, fldDate) 
					SELECT        ID,fldRadif, fldShomareFactor, fldCodeTafsili, fldCodeKala, fldTedadJoz, fldFeeJoz, fldFeeKol, fldMablaghTakhfif, fldFeeVahed1BadAzTakhfif, fldArzeshAfzode, fldFeeKolBadAzTakhfif, 
											 fldMablaghKhales, fldDate
					FROM            tblRizeForoosh where flddate between @dateaz and @dateta

	
			
	
--  -1 تایید نشده	
--   0 ارسال نشده
--   1 تایید شده
--   2 ارسالی وضعیت نامشخص
--   3 همه




	update #TempShow set fldSharheTafzili=tblTafzili.fldSharheTafzili from tblTafzili where #TempShow.fldCodeTafsili=tblTafzili.fldCodeTafzili

	update #TempShow set fldNameKala=tblKala.fldNameKala from tblKala where #TempShow.fldCodeKala=tblKala.fldCodeKala

	update #TempShow set fldShenaseKala=tblKala.fldShenase from tblKala where #TempShow.fldCodeKala=tblKala.fldCodeKala

	update #TempShow set #TempShow.fldRefrenceMoadian=tblForoosh.fldRefrenceMoadianAsli ,#TempShow.fldTaeidMoadian=tblForoosh.fldTaeidMoadianAsli from tblforoosh where fldShomareFactor=tblForoosh.fldShomareFactorForoosh 


	--case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=0 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده'
	if @Vaziat=3		--همه
		select ID ,fldRadif ,fldShomareFactor ,fldCodeTafsili ,fldSharheTafzili ,fldCodeKala ,fldShenaseKala ,fldNameKala ,fldTedadJoz ,fldFeeJoz ,fldFeeKol, fldMablaghTakhfif,
			   fldFeeVahed1BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldDate,fldShomareEghtesadi,fldRefrenceMoadian,fldTaeidMoadian,case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=2 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده' end as vaziatTaeid
				from #TempShow order by fldShomareFactor,fldRadif
	else if @Vaziat=-0 --ارسال نشده
		select ID ,fldRadif ,fldShomareFactor ,fldCodeTafsili ,fldSharheTafzili ,fldCodeKala ,fldShenaseKala ,fldNameKala ,fldTedadJoz ,fldFeeJoz ,fldFeeKol, fldMablaghTakhfif,
			   fldFeeVahed1BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldDate,fldShomareEghtesadi,fldRefrenceMoadian,fldTaeidMoadian,case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=2 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده' end as vaziatTaeid
				from #TempShow where fldTaeidMoadian is NULL order by fldShomareFactor,fldRadif  
	else
		select ID ,fldRadif ,fldShomareFactor ,fldCodeTafsili ,fldSharheTafzili ,fldCodeKala ,fldShenaseKala ,fldNameKala ,fldTedadJoz ,fldFeeJoz ,fldFeeKol, fldMablaghTakhfif,
			   fldFeeVahed1BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldDate,fldShomareEghtesadi,fldRefrenceMoadian,fldTaeidMoadian,case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=2 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده' end as vaziatTaeid
				from #TempShow where fldTaeidMoadian =@Vaziat order by fldShomareFactor,fldRadif  
end
GO

-- ===============================================
-- SP: [dbo].[ShowMoadianPishFactor]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowMoadianPishFactor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowMoadianPishFactor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowMoadianPishFactor]

@Vaziat int,
@DateAz int,
@DateTa int,
@Asli int
--@mmm nvarchar(30),
--@IDOutPut int outPut
as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin
create table #TempShow(

ID bigint,
fldRadif bigint,
fldShomareFactor bigint,
fldCodeTafsili nvarchar(100) COLLATE Persian_100_CI_AS,
fldSharheTafzili nvarchar(250) COLLATE Persian_100_CI_AS,
fldCodeKala bigint,
fldShenaseKala nvarchar(50),
fldNameKala nvarchar(250) COLLATE Persian_100_CI_AS,
fldTedadJoz decimal(18, 2), 
fldFeeJoz decimal(18, 0), 
fldFeeKol decimal(18, 0),  
fldMablaghTakhfif decimal(18, 0),
fldFeeVahed1BadAzTakhfif decimal(18, 0),
fldArzeshAfzode decimal(18, 0),
fldDarsadArzeshAfzoode int,
fldFeeKolBadAzTakhfif decimal(18, 0),
fldMablaghKhales decimal(18, 0),
fldDate bigint,
fldShomareEghtesadi nvarchar(50),
fldType nvarchar(15),
fldRefrenceMoadian nvarchar(100),
fldTaeidMoadian int,
fldShenaseMaliatiFactor nvarchar(25),
fldDateSarResid bigint

)

	insert into #TempShow
				(ID,fldRadif, fldShomareFactor, fldCodeTafsili, fldCodeKala, fldTedadJoz, fldFeeJoz, fldFeeKol, fldMablaghTakhfif, fldFeeVahed1BadAzTakhfif, fldArzeshAfzode,fldDarsadArzeshAfzoode, fldFeeKolBadAzTakhfif, 
											 fldMablaghKhales, fldDate,fldType) 
					SELECT        ID,fldRadif, fldShomareFactor, fldCodeTafsili, fldCodeKala, fldTedadJoz, fldFeeJoz, fldFeeKol, fldMablaghTakhfif, fldFeeVahed1BadAzTakhfif, fldArzeshAfzode,fldDarsadArzeshAfzoode, fldFeeKolBadAzTakhfif, 
											 fldMablaghKhales, fldDate,fldType
					FROM            tblRizePishForoosh where flddate between @dateaz and @dateta

	
	update #TempShow set fldShomareEghtesadi=tblTafzili.fldCodeEghtesadi from tblTafzili where #TempShow.fldCodeTafsili=tblTafzili.fldCodeTafzili
	
--  -1 تایید نشده	
--   0 ارسال نشده
--   1 تایید شده
--   2 ارسالی وضعیت نامشخص
--   3 همه




	update #TempShow set fldSharheTafzili=tblTafzili.fldSharheTafzili from tblTafzili where #TempShow.fldCodeTafsili=tblTafzili.fldCodeTafzili

	update #TempShow set fldNameKala=tblKala.fldNameKala from tblKala where #TempShow.fldCodeKala=tblKala.fldCodeKala

	update #TempShow set fldShenaseKala=tblKala.fldShenase from tblKala where #TempShow.fldCodeKala=tblKala.fldCodeKala

	if @asli=1
		update #TempShow set #TempShow.fldRefrenceMoadian=tblPishForoosh.fldRefrenceMoadianAsli,#TempShow.fldShenaseMaliatiFactor=tblPishForoosh.fldShenaseMaliatiFactor ,#TempShow.fldTaeidMoadian=tblPishForoosh.fldTaeidMoadianAsli from tblPishForoosh where fldShomareFactor=tblPishForoosh.fldShomareFactorForoosh 
	else
		update #TempShow set #TempShow.fldRefrenceMoadian=tblPishForoosh.fldRefrenceMoadian ,#TempShow.fldShenaseMaliatiFactor=tblPishForoosh.fldShenaseMaliatiFactor,#TempShow.fldTaeidMoadian=tblPishForoosh.fldTaeidMoadian from tblPishForoosh where fldShomareFactor=tblPishForoosh.fldShomareFactorForoosh 

	update #TempShow set fldDateSarresid =0
	update #TempShow set fldDateSarResid=tblSarResidMoadian.fldDate from tblSarResidMoadian where #TempShow.fldShomareFactor=tblSarResidMoadian.fldShomareFactor
	--case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=0 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده'
	if @Vaziat=3		--همه
		select ID ,fldRadif ,fldShomareFactor ,fldCodeTafsili ,fldSharheTafzili ,fldCodeKala ,fldShenaseKala ,fldNameKala ,fldTedadJoz ,fldFeeJoz ,fldFeeKol, fldMablaghTakhfif,
			   fldFeeVahed1BadAzTakhfif,fldArzeshAfzode,fldDarsadArzeshAfzoode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldDate,fldShomareEghtesadi,fldType,fldRefrenceMoadian,fldTaeidMoadian,case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=2 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده' end as vaziatTaeid,fldShenaseMaliatiFactor,fldDateSarResid
				from #TempShow order by fldShomareFactor,fldRadif
	else if @Vaziat=-0 --ارسال نشده
		select ID ,fldRadif ,fldShomareFactor ,fldCodeTafsili ,fldSharheTafzili ,fldCodeKala ,fldShenaseKala ,fldNameKala ,fldTedadJoz ,fldFeeJoz ,fldFeeKol, fldMablaghTakhfif,
			   fldFeeVahed1BadAzTakhfif,fldArzeshAfzode,fldDarsadArzeshAfzoode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldDate,fldShomareEghtesadi,fldType,fldRefrenceMoadian,fldTaeidMoadian,case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=2 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده' end as vaziatTaeid,fldShenaseMaliatiFactor,fldDateSarResid
				from #TempShow where fldTaeidMoadian is NULL order by fldShomareFactor,fldRadif  
	else
		select ID ,fldRadif ,fldShomareFactor ,fldCodeTafsili ,fldSharheTafzili ,fldCodeKala ,fldShenaseKala ,fldNameKala ,fldTedadJoz ,fldFeeJoz ,fldFeeKol, fldMablaghTakhfif,
			   fldFeeVahed1BadAzTakhfif,fldArzeshAfzode,fldDarsadArzeshAfzoode,fldFeeKolBadAzTakhfif,fldMablaghKhales,fldDate,fldShomareEghtesadi,fldType,fldRefrenceMoadian,fldTaeidMoadian,case when fldTaeidMoadian=1 then 'تایید' when fldTaeidMoadian=2 then 'وضعیت نامشخص' when fldTaeidMoadian=-1 then 'عدم تایید' when fldTaeidMoadian is null then 'ارسال نشده' end as vaziatTaeid,fldShenaseMaliatiFactor,fldDateSarResid
				from #TempShow where fldTaeidMoadian =@Vaziat order by fldShomareFactor,fldRadif  
end
GO

-- ===============================================
-- SP: [dbo].[ShowMoghayerat]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowMoghayerat', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowMoghayerat] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
Alter PROCEDURE [dbo].[ShowMoghayerat] 

AS
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END

BEGIN
	
	create  table	#tblTemp(
		fldcodekala bigint,
		fldNameKala nvarchar(250),
		fldTedadeJoz decimal(18,2),
		fldTedadeKol nvarchar(100),
		fldTedadDarKarton decimal(18,2),
		fldType nvarchar(20),
		fldCodeAnbar bigint,
		fldNameAnbar nvarchar(150)	,
		fldCodeVahed1 bigint,
		fldCodeVahed2 bigint,
		fldNameVahed nvarchar(100),
		fldNameVahed2 nvarchar(100)
	)

	delete #tblTemp

	 insert into #tblTemp
		(fldcodekala ,fldTedadeJoz,fldType,fldCodeAnbar)
		select fldCodeKala,fldTedadJoz,N'کاهش',fldCodeAnbar from tblRizeForoosh where fldType='Moghayrat'

	insert into #tblTemp
		(fldcodekala ,fldTedadeJoz,fldType,fldCodeAnbar)
		select fldCodeKala,fldTedadJoz,N'افزایش',fldCodeAnbar from tblRizeKharid where fldType='Moghayrat'


	update #tblTemp set fldNameKala=tblKala.fldNameKala from tblkala where #tblTemp.fldcodekala=tblKala.fldCodeKala
	update #tblTemp set fldNameAnbar=tblAnbar.fldNameAnbar from tblAnbar where #tblTemp.fldCodeAnbar=tblAnbar.fldCode
	update #tblTemp set fldTedadDarKarton=tblKala.fldTedadJoz from  tblKala where #tblTemp.fldcodekala=tblKala.fldCodeKala
	update #tblTemp set fldCodeVahed1=tblKala.fldCodeVahed1,fldCodeVahed2=tblKala.fldCodeVahed2 from  tblKala where #tblTemp.fldcodekala=tblKala.fldCodeKala


	update #tbltemp set fldnamevahed2=N'' where fldNameVahed2=N'انتخاب کنید'
	update #tblTemp set fldNameVahed=tblVahed.fldNameVahed from  tblVahed where #tblTemp.fldCodeVahed1=tblVahed.ID
	update #tblTemp set fldNameVahed2=tblVahed.fldNameVahed from  tblVahed where #tblTemp.fldCodeVahed2=tblVahed.ID


	update #tblTemp set fldTedadDarKarton=0 where fldTedadDarKarton is NULL

	update #tblTemp Set fldTedadeKol=Convert(varchar,floor(fldTedadeJoz / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,fldTedadeJoz), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

	update #tblTemp set fldTedadekol='' where fldTedadekol is NULL

	select fldcodekala ,fldNameKala ,fldTedadeJoz,fldTedadeKol ,fldTedadDarKarton,fldType,fldCodeAnbar,fldNameAnbar from #tblTemp

END
GO

-- ===============================================
-- SP: [dbo].[ShowMojodiAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowMojodiAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowMojodiAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
Alter 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),@SumAllkhorooj decimal(16,2)
declare @SumAllTolidAvalie decimal(16,2)
declare @SumAllKharid decimal(16,2)
declare @SumAllTolidNahaei decimal(16,2)
declare @SumAllBargashtAzForoosh decimal(16,2)
declare @SumAllBargashtAzKharid decimal(16,2)
declare @MandehMojodi decimal(16,2)
declare @SumAllForoosh2 decimal(16,2),@SumAllkhorooj2 decimal(16,2)
declare @SumAllTolidAvalie2 decimal(16,2)
declare @SumAllBargashtAzForoosh2 decimal(16,2)
declare @SumAllKharid2 decimal(16,2)
declare @SumAllTolidNahaei2 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 @SumAllkhorooj=(select Isnull(sum(fldTedadJoz),0) from tblRizHavaleHazine where fldCodeKala=@CodeKala)
   set @SumAllTolidAvalie=(select Isnull(sum(fldTedadJozAvalie),0) from tblRizeTolid 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 @SumAllTolidNahaei=(select Isnull(sum(fldTedadJozNahaei),0) from tblRizeTolid  where fldCodeKala=@CodeKala)
   set @SumAllBargashtAzKharid=(select Isnull(sum(fldTedadJoz),0) from tblRizeBargashtAzKharid  where fldCodeKala=@CodeKala)   
   set @MandehMojodi=@SumAllKharid+@SumAllTolidNahaei+@SumAllBargashtAzForoosh - @SumAllForoosh-@SumAllkhorooj-@SumAllBargashtAzKharid-@SumAllTolidAvalie
   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 @SumAllkhorooj2=(select Isnull(sum(fldTedadJoz),0) from tblRizHavaleHazine where fldCodeKala=@CodeKala And fldCodeAnbar=@CodeAnbar)	 
	 set @SumAllTolidAvalie=(select Isnull(sum(fldTedadJozAvalie),0) from tblRizeTolid 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 @SumAllTolidNahaei=(select Isnull(sum(fldTedadJozNahaei),0) from tblRizeTolid 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+@SumAllTolidNahaei - @SumAllForoosh2-@SumAllkhorooj2-@SumAllBargashtAzKharid2-@SumAllTolidAvalie
	 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 @SumAllTolidNahaei=(select Isnull(sum(fldTedadJozNahaei),0) from tblRizeTolid  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 @SumAllkhorooj=(select Isnull(sum(fldTedadJoz),0) from tblRizHavaleHazine where fldCodeKala=@CodeKala And fldCodeAnbar=@CodeAnbar)
	set @SumAllTolidAvalie=(select Isnull(sum(fldTedadJozAvalie),0) from tblRizeTolid 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+@SumAllTolidNahaei - @SumAllForoosh-@SumAllkhorooj-@SumAllBargashtAzKharid-@SumAllTolidAvalie
    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 @SumAllkhorooj=(select Isnull(sum(fldTedadJoz),0) from tblRizHavaleHazine where fldCodeKala=@CodeKala and fldCodeAnbar=@CodeAnbar)
	   set @SumAllTolidAvalie=(select Isnull(sum(fldTedadJozAvalie),0) from tblRizeTolid 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 @SumAllTolidNahaei=(select Isnull(sum(fldTedadJozNahaei),0) from tblRizeTolid  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 +@SumAllTolidNahaei - @SumAllForoosh-@SumAllkhorooj-@SumAllBargashtAzKharid-@SumAllTolidAvalie
	   set @ReturnAllAnbar=@MandehMojodi
	   Return @ReturnAllAnbar
	 end
	 
END
GO

-- ===============================================
-- SP: [dbo].[ShowMojodiAnbarTaTarikh]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowMojodiAnbarTaTarikh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowMojodiAnbarTaTarikh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
Alter PROCEDURE [dbo].[ShowMojodiAnbarTaTarikh] 
@CodeKala bigint,
@CodeAnbar bigint,
@TypeShow nvarchar(40),
@DateTa bigint,
@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 @SumAllTolidAvalie decimal(16,2)
declare @SumAllTolidNahaei 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 And fldDate<=@DateTa)
   set @SumAllBargashtAzForoosh=(select Isnull(sum(fldTedadJoz),0) from tblRizeBargashtAzForoosh where fldCodeKala=@CodeKala And fldDate<=@DateTa)
   set @SumAllKharid=(select Isnull(sum(fldTedadJoz),0) from tblRizeKharid  where fldCodeKala=@CodeKala And fldDate<=@DateTa)
   set @SumAllBargashtAzKharid=(select Isnull(sum(fldTedadJoz),0) from tblRizeBargashtAzKharid  where fldCodeKala=@CodeKala And fldDate<=@DateTa)   

   set @SumAllTolidAvalie=(select Isnull(sum(fldTedadJozAvalie),0) from tblRizeTolid  where fldCodeKala=@CodeKala And fldDate<=@DateTa)  
   set @SumAllTolidNahaei=(select Isnull(sum(fldTedadJozNahaei),0) from tblRizeTolid  where fldCodeKala=@CodeKala And fldDate<=@DateTa)  
    
   set @MandehMojodi=@SumAllKharid+@SumAllBargashtAzForoosh+@SumAllTolidNahaei - @SumAllForoosh-@SumAllBargashtAzKharid-@SumAllTolidAvalie
   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

-- ===============================================
-- SP: [dbo].[ShowPardakhtInfo]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowPardakhtInfo', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowPardakhtInfo] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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,

@karmozd decimal 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 if @strtype='hazine'
			set @SharheKol=(Select top(1)fldSharh from tblSodooreSanad Where fldSanad=@ShomareSanad And fldBedehkar>0)
		else if @strtype='enteghalevajh'
			set @SharheKol=(Select top(1)fldSharh from tblSodooreSanad Where fldSanad=@ShomareSanad And fldBedehkar>0)
		else 
			set @SharheKol=(Select fldSharh from tblSodooreSanad Where fldSanad=@ShomareSanad And fldBedehkar>0 and fldMoinKamel=@CodeMoinHesabhayePardakhtani)



		set @CodeVasete=(Select top(1)isnull(fldVasete,'') from tblSodooreSanad Where fldSanad=@ShomareSanad And fldBedehkar>0 and isnumeric(fldVasete)=1)
		--select * from tblsodooresanad where fldsanad
		--صندوق
		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 top(1) isnull(fldBestankar,0) from tblSodooreSanad Where fldCodeKol=@KolBank and fldSanad=@ShomareSanad and fldBestankar>0 order by id )
		set @CodeMoinBank=(Select top(1)  fldMoinKamel from tblSodooreSanad Where fldCodeKol=@KolBank and fldSanad=@ShomareSanad and fldBestankar>0 and fldBestankar>0 order by id)		
		set @SBank=(Select top(1)  isnull(fldSharh,'') from tblSodooreSanad Where fldCodeKol=@KolBank and fldSanad=@ShomareSanad and fldBestankar>0 and fldBestankar>0 order by id)		
		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 and fldBestankar>0)
		
		--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 and fldBestankar>0)		
		if @strMablagh is null
			begin			
				set @MablaghCheck=0
				--set @CodeMoincheck=''
				set @Scheck=''
			end
		else
			begin			
				set @MablaghCheck=Convert(dec,@strMablagh)
			end

		declare @KolMoincheck2 nvarchar(10)
		--چک واگذاری مشتریان
		if @strtype='hazine' 
			execute CodeMoinHesab  'checkvagozaripersonel', @KolMoincheck output
		else if  @strtype='pardakhtsayer'
			begin
				execute CodeMoinHesab  'check', @KolMoincheck output
				execute CodeMoinHesab  'checkvagozaripersonel', @KolMoincheck2 output
			end
		else
			execute CodeMoinHesab  'check', @KolMoincheck output


		set @strMablagh=(Select sum(isnull(fldBestankar,0)) as sumMablagh from tblSodooreSanad Where (fldMoinKamel=@KolMoincheck or fldMoinKamel=@KolMoincheck2) 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)		
		set @SCheckVagozari=(Select top(1)isnull(fldSharh,'') from tblSodooreSanad Where (fldMoinKamel=@KolMoincheck or fldMoinKamel=@KolMoincheck2) 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


		--کارمزد بانک
		execute CodeMoinHesab  'karmozd', @KolMoinTakhfif output
		set @strMablagh=(Select isnull(fldBedehkar,0) from tblSodooreSanad Where fldMoinKamel=@KolMoinTakhfif and fldSanad=@ShomareSanad)
		if @strMablagh is null
			begin			
				set @karmozd=0				
			end
		else
			begin			
				set @karmozd=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

-- ===============================================
-- SP: [dbo].[ShowSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowSanad]

@Sanad nvarchar(50)
as 

begin

	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, fldDateUpdate, fldColorBank, fldColorSandoogh, fldColorSooratHesab,fldShomareTolid,fldCodeVasete2
		FROM  tblSodooreSanad where fldSanad=@Sanad
	
end
GO

-- ===============================================
-- SP: [dbo].[ShowSandooghAndBankInFormVosoolCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowSandooghAndBankInFormVosoolCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowSandooghAndBankInFormVosoolCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ShowSandooghNew]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowSandooghNew', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowSandooghNew] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[ShowSandooghNew]
@CodeKolHesab nvarChar(8)
as
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
begin
	
	create table #tblTemp (
		[fldCodeHesab] nvarchar(100) COLLATE Persian_100_CI_AS,
		[fldSharheHesab] nvarchar(max) COLLATE Persian_100_CI_AS,
		[ID] bigint,
		fldinfo nvarchar(100) COLLATE Persian_100_CI_AS,
		fldMande decimal(18,2),
		fldUnActive int
	
	)
	insert into #tblTemp (fldCodeHesab,[fldSharheHesab],[ID],fldinfo,fldUnActive )
		select [fldCodeHesab],[fldSharheHesab],[ID],fldinfo,fldUnActive from tblKolMoin
			Where fldCodeHesab<>@CodeKolHesab and left(fldCodeHesab,len(@CodeKolHesab))=@CodeKolHesab
			order by fldUnActive,fldCodeHesab

	--select * from #tblTemp

	update #tblTemp set fldMande= tbl1.fldBedehkar from 
		(select fldBedehkar,fldMoinKamel from tblSodooreSanad Where fldtype='mandesandoogh') as tbl1
		where tbl1.fldMoinKamel=#tblTemp.fldCodeHesab

	update #tblTemp set fldMande=0 where fldMande Is NUll

	select 		[fldCodeHesab] ,[fldSharheHesab] ,[ID],fldinfo ,fldMande,fldUnActive  from #tblTemp order by fldUnActive,fldCodeHesab
end
GO

-- ===============================================
-- SP: [dbo].[ShowShomareFish]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowShomareFish', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowShomareFish] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ShowTanzimatNew]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowTanzimatNew', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowTanzimatNew] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowTanzimatNew]

	@Name1 nvarChar(30),
	@Meghdar nvarChar(100) OutPut	
as 

begin
	
	Set @Meghdar=(Select fldMeghdar from tblTanzimatNew Where fldName=@Name1)
	if @meghdar is  null
		begin
			set @meghdar='NOTHING'	
		end

end
GO

-- ===============================================
-- SP: [dbo].[ShowTanzimatUser]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowTanzimatUser', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowTanzimatUser] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[ShowTanzimatUser]
	@User bigint,
	@fldSharh nvarChar(100),
	@Meghdar nvarChar(30) OutPut	
as 

begin
	
	Set @Meghdar=(Select top(1)fldMeghdar from tblTanzimateuser Where fldSharh=@fldSharh and fldUser=@user)
	if @meghdar is  null
		begin
			set @meghdar='NOTHING'	
		end

end
GO

-- ===============================================
-- SP: [dbo].[ShowtblTarheTakhfif]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowtblTarheTakhfif', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowtblTarheTakhfif] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[ShowtblTarheTakhfif]
--@CodeKolHesab nvarChar(8)
as
begin
	select Id,fldMablagh,fldDarsad,countRow from tblTarheTakhfif
	ORDER BY fldMablagh 
		--Where fldCodeHesab<>@CodeKolHesab and left(fldCodeHesab,len(@CodeKolHesab))=@CodeKolHesab
		
end
GO

-- ===============================================
-- SP: [dbo].[ShowtblTarheTakhfifeRadifi]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowtblTarheTakhfifeRadifi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowtblTarheTakhfifeRadifi] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[ShowtblTarheTakhfifeRadifi]
--@CodeKolHesab nvarChar(8)
as
begin
	select Id,fldMablagh,fldDarsad,countRow from tblTarheTakhfifeRadifi
	ORDER BY fldMablagh 
		--Where fldCodeHesab<>@CodeKolHesab and left(fldCodeHesab,len(@CodeKolHesab))=@CodeKolHesab
		
end
GO

-- ===============================================
-- SP: [dbo].[ShowUsers]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowUsers', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowUsers] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[ShowVahed]
-- ===============================================
IF OBJECT_ID(N'dbo.ShowVahed', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ShowVahed] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[ShowVahed]

as
begin
	select [fldNameVahed],[ID] from tblVahed
		where id<>1
		order by id
end
GO

-- ===============================================
-- SP: [dbo].[SoodeFactor]
-- ===============================================
IF OBJECT_ID(N'dbo.SoodeFactor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[SoodeFactor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[SoodeFactor]

@dtForoosh tpRizeForoosh  readonly,
@Sood bigint output
as 
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END

begin

	--create table #tmpForoosh(
	--	CodeKala bigint,
	--	fldTedadJoz bigint,
	--	fldFeeTakhfifVahed1 bigint,
	--	fldLastFeeKharid
	--)
	
	declare @EmpRadif int,@EmpR bigint,@bigLastFeeKharid decimal,@bigLastFeeForoosh decimal,@CodeKala2 bigint,@bigTedad decimal, @bigSumSood decimal
	set @bigSumSood=0
	
	CREATE TABLE #TempTable (  
    -- ستون‌ها و نوع داده‌ها را بر اساس خروجی stored procedure تعریف کنید  
    fldMablaghKhales decimal(18,2),  
    fldArzeshAfzode decimal(18,2),  
    fldTedadJoz decimal(18,2),  
	fldDate int 
);  

    declare EmpCursor Cursor For
            Select fldRadif from @dtForoosh 
        		open EmpCursor
        		fetch Next From EmpCursor into @EmpR
        		While @@Fetch_Status = 0
        			Begin	
						declare @Tedad as decimal
        				set @CodeKala2=(Select fldCodeKala from @dtForoosh Where fldRadif=@EmpR)       
						--update tblrizeKharid set fldMablaghKhales=fldfeeKol Where fldType='mojodi_ebteda_doreh'	 				        				        				
        				--set @bigLastFeeKharid=(Select top(1) fldMablaghKhales/fldTedadJoz  from tblRizeKharid Where fldtype<>'enteghal' and fldCodeKala=@CodeKala and fldFeeJoz<>0 order by fldDate desc,ID desc)
						
						delete #TempTable

						INSERT INTO #TempTable  
							EXEC LastFeeKharidVaTolid @codekala = @codekala2; 


						--SELECT TOP 1 *  
						--FROM #TempTable

						set @bigLastFeeKharid=(Select top(1) (fldMablaghKhales-fldArzeshAfzode) /fldTedadJoz  from #TempTable )
						--set @bigLastFeeKharid=(select * from LastFeeKharidVaTolid(@CodeKala2))
        				if ISNUMERIC(@bigLastFeeKharid)=0
        					set @bigLastFeeKharid=0


						set @Tedad=(Select fldTedadJoz from @dtForoosh Where fldRadif=@EmpR)
						if @tedad>0 
							begin
        						set @bigLastFeeForoosh=(Select fldMablaghKhales/fldTedadJoz from @dtForoosh Where fldRadif=@EmpR)
        						set @bigTedad=(Select fldTedadJoz from @dtForoosh Where fldRadif=@EmpR)
        					end
        				else
							begin
								set @bigLastFeeForoosh=0
        						set @bigTedad=0
							end
        				
							
        				set @bigSumSood =@bigSumSood + (@bigLastFeeForoosh-@bigLastFeeKharid)*@bigTedad
       -- 				INSERT INTO tblTest7
							--(fld1, fld2, fld3)
							--VALUES     (@bigLastFeeKharid,@bigLastFeeForoosh,@bigSumSood)
        				
        				--update #TempListeAshkhas3  set  fldTell=(Select top(1)  fldShomare from tblDaftarcheTell Where fldCodetafzili=@EmpCodeTafzili)
        				--		where fldCodetafzili =@EmpCodeKala
        				Fetch Next from EmpCursor
        			into @EmpR
        		end
        Close EmpCurSor
        Deallocate EmpCursor
	
	if isnumeric(@bigSumSood)=1
		set @Sood=@bigSumSood
	else
		set @Sood=0
	--set @Sood=10
end
GO

-- ===============================================
-- SP: [dbo].[SoodeGroupFifo]
-- ===============================================
IF OBJECT_ID(N'dbo.SoodeGroupFifo', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[SoodeGroupFifo] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[SoodeGroupFifo](@DateFROM BIGINT,@DateTo BIGINT, @ListCodeAnbar VARCHAR(5000),@fldCodekala bigint, @fldCodeGroup bigint)
AS
BEGIN
--Declare	@DateFROM BIGINT=13980101,@DateTo BIGINT = 19990101;
--DECLARE	@ListCodeAnbar VARCHAR(5000)=NULL;
--DECLARE @fldCodekala bigint =  NULL;--10080 --10004; -- NULL

SET NOCOUNT ON

CREATE Table	#KardeksTable ([ID] BIGINT, [fldSharh] NVARCHAR(200) COLLATE Persian_100_CI_AS, 
		[fldtypeShow] NVARCHAR(40) COLLATE Persian_100_CI_AS, [fldShomareFactor] BIGINT, [fldDateShow] NVARCHAR(25),
		[fldTedadeJozVorood] decimal(18,2), [fldTedadeJozKhorooj] decimal(18,2), [SumMandeJoz] decimal(18,2),
		[fldNameVahed] NVARCHAR(100) COLLATE Persian_100_CI_AS, [fldFeeJoz] BIGINT, [fldFeeVahed1BadAzTakhfif] BIGINT,
		[fldFeeYekKarton] BIGINT, [fldMablaghKol] BIGINT, [fldTedadVoroodKartonShow] NVARCHAR(100) COLLATE Persian_100_CI_AS,
		[fldTedadKhoroojKartonShow] NVARCHAR(100) COLLATE Persian_100_CI_AS, [fldTedadDarKarton] BIGINT,
		[fldNameVahed2] NVARCHAR(100) COLLATE Persian_100_CI_AS, [fldKolMande] NVARCHAR(100) COLLATE Persian_100_CI_AS,
		[fldShomareSanad] BIGINT, [fldCodeAnbar] BIGINT, [fldNameAnbar] NVARCHAR(50) COLLATE Persian_100_CI_AS,  [fldDate] BIGINT,
		[fldtype] NVARCHAR(20) COLLATE Persian_100_CI_AS, [fldRadif] BIGINT, [IdOrder] BIGINT, [fldCodeTafsili] BIGINT,
		[CodeKala] BIGINT NULL, [NameKala] NVARCHAR(100) COLLATE Persian_100_CI_AS, [CodeGroup] BIGINT, [NameGroup] NVARCHAR(80) COLLATE Persian_100_CI_AS,
		[fldShomareEnteghal] BIGINT, [fldTedadeJozVoroodT] NVARCHAR(10), [fldTedadeJozKhoroojT] NVARCHAR(10), [fldTedadDarKartonShow] NVARCHAR(100) COLLATE Persian_100_CI_AS, 
		[SumMandeJozT] NVARCHAR(100),  [fldJozMande] BIGINT, [ConditionSum] BIGINT);

with cte as
(SELECT	Buy.ID,fldCodeTafsili,Buy.fldCodeKala, fldShomareFactor,fldShomareEnteghal,fldShomareSanad,fldDate, '' [fldSharh],fldCodeAnbar, fldFeeJoz,
		fldFeeVahed1BadAzTakhfif, fldFeeYekCarton,fldMablaghKhales [fldMablaghKol],Buy.fldTedadJoz [fldTedadeJozVorood],0 [fldTedadeJozKhorooj],
		fldtype, NULL [fldRadif]
FROM	tblRizeKharid Buy
UNION ALL
SELECT	NULL ID, 0 [fldCodeTafsili],[Produce].fldCodeKala, fldShomareTolid fldShomareFactor, 0 [fldShomareEnteghal], fldShomareSanad,fldDate,
		'' [fldSharh], fldCodeAnbar, fldFeeJoz,fldFeeVahed1BadAzTakhfif,fldFeeYekCarton,fldMablaghKhales [fldMablaghKol], fldTedadJozNahaei [fldTedadeJozVorood],
		0 [fldTedadeJozKhorooj], fldtype, NULL [fldRadif]
FROM	tblRizeTolid Produce
WHERE	fldType='mahsool'
UNION ALL
SELECT	NULL ID, fldCodeTafsili, [ReSell].fldCodeKala,fldShomareFactor, 0 [fldShomareEnteghal], fldShomareSanad, fldDate, '' [fldSharh], fldCodeAnbar,
		fldFeeJoz, fldFeeVahed1BadAzTakhfif, fldFeeYekCarton,fldMablaghKhales [fldMablaghKol], [ReSell].fldTedadJoz [fldTedadeJozVorood], 0 [fldTedadeJozKhorooj],
		'bargashtazforoosh' [fldtype], NULL [fldRadif]
FROM	tblRizeBargashtAzForoosh [ReSell]
UNION ALL
SELECT	[Sell].id [ID], fldCodeTafsili,[Sell].fldCodeKala, [fldShomareFactor], fldShomareEnteghal, fldShomareSanad, fldDate,'' [fldSharh], fldCodeAnbar,
		fldFeeJoz, fldFeeVahed1BadAzTakhfif,fldFeeYekCarton, fldMablaghKhales [fldMablaghKol], 0 [fldTedadeJozVorood], [Sell].fldTedadJoz [fldTedadeJozKhorooj],
		fldtype, fldRadif
FROM	tblRizeForoosh [Sell]
UNION ALL
SELECT	NULL [ID], 0 [fldCodeTafsili],[Produce].fldCodeKala, fldShomareTolid [fldShomareFactor], 0 [fldShomareEnteghal], fldShomareSanad,
		fldDate,'' [fldSharh], fldCodeAnbar, fldFeeJoz, fldFeeVahed1BadAzTakhfif, fldFeeYekCarton, fldMablaghKhales [fldMablaghKol],
		0 [fldTedadeJozVorood], fldTedadJozAvalie [fldTedadeJozKhorooj], fldtype,fldRadif
FROM	tblRizeTolid [Produce]
WHERE	fldType='avalie'
UNION ALL
SELECT	NULL [ID], fldCodeTafsili, [ReBuy].fldCodeKala, fldShomareFactor, NULL [fldShomareEnteghal], fldShomareSanad,fldDate,'' [fldSharh], fldCodeAnbar,
		fldFeeJoz, fldFeeVahed1BadAzTakhfif, fldFeeYekCarton, fldMablaghKhales [fldMablaghKol], 0 [fldTedadeJozVorood], [ReBuy].fldTedadJoz [fldTedadeJozKhorooj],
		'bargashtazkharid' [fldtype], NULL fldRadif
FROM	tblRizeBargashtAzKharid [ReBuy])
INSERT	INTO #KardeksTable
SELECT	cte.[ID],
		[Tafzili].fldSharheTafzili + ' '+ CASE WHEN [fldType]='Moghayrat' THEN 'مغایرت' ELSE cte.[fldSharh] END [fldSharh],
		CASE [fldType]	WHEN 'kharid' THEN 'خرید'
				WHEN 'mojodi_ebteda_doreh' THEN'ابتدای دوره'
				WHEN 'enteghal' THEN 'انتقال بین انبار'
				WHEN 'foroosh' THEN 'فروش'
				WHEN 'bargashtazforoosh' THEN 'برگشت از فروش'
				WHEN 'bargashtazkharid' THEN 'برگشت از خرید'
				WHEN 'avalie' THEN 'تبدیل به محصول نهایی'
				WHEN 'mahsool' THEN 'محصول تولید شده در فرایند تولید'
				WHEN 'Moghayrat' THEN 'مغایرت' END [fldTypeShow],
		CASE WHEN fldType='enteghal' THEN [fldShomareEnteghal] ELSE [fldShomareFactor] END [fldShomareFactor],
		SUBSTRING(CONVERT(NVARCHAR(10),fldDate),0,5) +'/' +SUBSTRING(CONVERT(NVARCHAR(10),fldDate),5,2) + '/' + SUBSTRING(CONVERT(NVARCHAR(10),fldDate),7,2) [flddateshow],
		[fldTedadeJozVorood], [fldTedadeJozKhorooj],
		NULL SumMandeJoz,
		[Vahed1].fldNameVahed [fldNameVahed], [fldFeeJoz], [fldFeeVahed1BadAzTakhfif], [fldFeeYekCarton], [fldMablaghKol],
		CASE WHEN fldTedadeJozVorood > 0 THEN CASE WHEN [Stuff].fldTedadJoz > 0 THEN CONVERT(VARCHAR,floor(fldTedadeJozVorood / [Stuff].fldTedadJoz)) + ' ' + [Vahed2].fldNameVahed +  CONVERT(VARCHAR, { fn MOD(CONVERT(DEC,fldTedadeJozVorood), [Stuff].fldTedadJoz) } ) + ' ' + [Vahed1].fldNameVahed ELSE '' END ELSE '' END [fldTedadVoroodKartonShow],
		CASE WHEN fldTedadeJozKhorooj > 0 THEN CASE WHEN [Stuff].fldTedadJoz > 0 THEN CONVERT(VARCHAR,floor(fldTedadeJozKhorooj / [Stuff].fldTedadJoz)) + ' ' + [Vahed2].fldNameVahed +  CONVERT(VARCHAR, { fn MOD(CONVERT(DEC,fldTedadeJozKhorooj), [Stuff].fldTedadJoz) } ) + ' ' + [Vahed1].fldNameVahed ELSE '' END ELSE '' END [fldTedadKhoroojKartonShow],
		[Stuff].fldTedadJoz [fldTedadDarKarton], CASE WHEN [Stuff].fldTedadJoz=0 THEN '' ELSE [Vahed2].fldNameVahed END [fldNameVahed2],
		NULL [fldKolMande],
		[fldShomareSanad], [fldCodeAnbar],[Anbar].[fldNameAnbar], [fldDate], [fldtype], fldRadif,
		CONVERT(VARCHAR,CONVERT(BIGINT, CONVERT(VARCHAR,fldDate) + CONVERT(VARCHAR, fldShomareSanad))) +
			CASE WHEN fldtype='enteghal' THEN fldShomareEnteghal ELSE '' END IdOrder,
		CASE WHEN [fldType]='Moghayrat' THEN 0 ELSE fldCodeTafsili END fldCodeTafsili, cte.fldCodeKala [CodeKala],[Stuff].fldNameKala [NameKala],
		[Stuff].fldCodeGroup [CodeGroup], [StuffGroup].fldGroupName [NameGroup], [fldShomareEnteghal],
		NULL [fldTedadeJozVoroodT], NULL [fldTedadeJozKhoroojT], NULL [fldTedadDarKartonShow], 
		NULL [SumMandeJozT], -1 [fldJozMande], 1 [ConditionSum]
FROM	cte
		LEFT JOIN tblKala [Stuff] ON [cte].fldCodeKala=[Stuff].fldCodeKala
		LEFT JOIN tblGroupKala [StuffGroup] ON [Stuff].fldCodeGroup=[StuffGroup].fldGroupId
		LEFT JOIN tblAnbar [Anbar] ON [Anbar].fldCode=[cte].fldCodeAnbar
		LEFT JOIN tblVahed [Vahed1] ON [Stuff].fldCodeVahed1=[Vahed1].ID
		LEFT JOIN tblVahed [Vahed2] ON [Stuff].fldCodeVahed2=[Vahed2].ID
		LEFT JOIN tblTafzili [Tafzili] ON cte.fldCodeTafsili=[Tafzili].fldCodeTafzili
WHERE	fldDate BETWEEN  @DateFROM  AND  @DateTo
		AND (@ListCodeAnbar IS NULL OR fldCodeAnbar IN (SELECT [Value] FROM dbo.SplitString(@ListCodeAnbar,',')))
		AND (@fldCodeKala IS NULL OR [Stuff].fldCodeKala = @fldCodekala)
		AND (@fldCodeGroup IS NULL OR [Stuff].fldCodeGroup LIKE CONVERT(nvarchar,@fldCodeGroup) + '%')

UPDATE #KardeksTable SET IdOrder=CONVERT(VARCHAR,IdOrder) + '1' WHERE LEN(IdOrder)=9 and fldTedadeJozVorood>0
UPDATE #KardeksTable SET IdOrder=CONVERT(VARCHAR,IdOrder) + '2' WHERE LEN(IdOrder)=9 and fldTedadeJozKhorooj>0

UPDATE	Result
SET		SumMandeJoz = Db.SumMandeJoz
FROM	#KardeksTable Result
		INNER JOIN
		(SELECT	a.CodeKala,a.IdOrder, SUM(b.fldTedadeJozVorood - b.fldTedadeJozKhorooj) SumMandeJoz
		FROM	#KardeksTable a
				CROSS Apply #KardeksTable b
		WHERE	a.CodeKala=b.CodeKala AND CONVERT(VARCHAR, b.IdOrder) <= CONVERT(VARCHAR, a.IdOrder)
		Group BY a.CodeKala,a.IdOrder) DB ON Result.IdOrder=DB.IdOrder AND Result.CodeKala=Db.CodeKala

UPDATE #KardeksTable SET SumMandeJozT=SumMandeJoz,fldTedadeJozVoroodT=fldTedadeJozVorood,fldTedadeJozKhoroojT=fldTedadeJozKhorooj
UPDATE #KardeksTable SET SumMandeJozT=LEFT(CONVERT(VARCHAR,SumMandeJoz),LEN(CONVERT(VARCHAR,SumMandeJoz))-3) WHERE RIGHT(CONVERT(VARCHAR,SumMandeJoz),2)='00'
UPDATE #KardeksTable SET fldTedadeJozVoroodT=LEFT(CONVERT(VARCHAR,fldTedadeJozVorood),LEN(CONVERT(VARCHAR,fldTedadeJozVorood))-3) WHERE right(CONVERT(VARCHAR,fldTedadeJozVorood),2)='00'
UPDATE #KardeksTable SET fldTedadeJozKhoroojT=LEFT(CONVERT(VARCHAR,fldTedadeJozKhorooj),LEN(CONVERT(VARCHAR,fldTedadeJozKhorooj))-3) WHERE right(CONVERT(VARCHAR,fldTedadeJozKhorooj),2)='00'
UPDATE #KardeksTable SET fldKolMande=CONVERT(VARCHAR,floor(SumMandeJoz / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  CONVERT(VARCHAR, { fn MOD(CONVERT(DEC,SumMandeJoz), fldTedadDarKarton) } ) + ' ' + fldNameVahed WHERE fldTedadDarKarton>0;

DECLARE	@ResultTable Table([CodeKala] bigint,[CodeGroup] bigint,SumBuyAmount decimal,
		SumBuyCount bigint,SumSellAmount decimal,SumSellCount bigint,SumReSellAmount decimal,SumReSellCount bigint,
		--ISNULL(SumBuyCount,0)+ISNULL(SumReSellCount,0)-ISNULL(SumSellCount,0) Temp,
		RemaindCount bigint,RemaindAtEnd bigint, StuffRemaindAtEnd bigint, SellAmountAtEnd decimal);

WITH CteOrder AS (SELECT ROW_NUMBER() OVER(Partition BY CodeKala ORDER BY flddate DESC,fldshomaresanad DESC) AS [Row],* FROM	#KardeksTable)
INSERT INTO @ResultTable
SELECT	[Stuff].fldCodeKala [CodeKala],fldCodeGroup [CodeGroup], SumBuyAmount,
		SumBuyCount,SumSellAmount,SumSellCount,SumReSellAmount,SumReSellCount,
		--ISNULL(SumBuyCount,0)+ISNULL(SumReSellCount,0)-ISNULL(SumSellCount,0) Temp,
		DbRemain.RemaindCount,RemaindAtEnd, NULL AS StuffRemaindAtEnd, NULL AS SellAmountAtEnd
FROM	[tblKala] [Stuff]
		LEFT JOIN	(SELECT	Res.[CodeKala],DB.SumMandeJoz RemaindCount
					FROM	CteOrder Res
							INNER JOIN CteOrder DB ON Res.CodeKala=DB.CodeKala AND Res.[Row]=Db.[Row]
					WHERE	DB.[Row]=1) DbRemain ON [Stuff].fldCodeKala=DbRemain.CodeKala
		Left JOIN	(SELECT	CodeKala, Sum(fldMablaghKol) SumBuyAmount
					FROM	#KardeksTable
					WHERE	fldtype IN ('Kharid', 'mojodi_ebteda_doreh')
					Group BY [CodeKala]) DbBuyAmount ON [Stuff].fldCodeKala=DbBuyAmount.CodeKala
		Left JOIN	(SELECT	CodeKala, Sum(fldTedadeJozVorood) SumBuyCount
					FROM	#KardeksTable
					WHERE	fldtype IN ('Kharid')
					Group BY [CodeKala]) DbBuyCount ON [Stuff].fldCodeKala=DbBuyCount.CodeKala
		Left JOIN	(SELECT	CodeKala, Sum(fldMablaghKol) SumSellAmount,Sum(fldTedadeJozKhorooj) SumSellCount
					FROM	#KardeksTable
					WHERE	fldtype ='Foroosh'
					Group BY [CodeKala]) DbSell ON [Stuff].fldCodeKala=DbSell.CodeKala
		Left JOIN	(SELECT	CodeKala, Sum(fldMablaghKol) SumReSellAmount,Sum(fldTedadeJozVorood) SumReSellCount
					FROM	#KardeksTable
					WHERE	fldtype ='bargashtazforoosh'
					Group BY [CodeKala]) DbReSell ON [Stuff].fldCodeKala=DbReSell.CodeKala
		Left JOIN	(SELECT	CodeKala,Sum(fldTedadeJozVorood) RemaindAtEnd
					FROM	#KardeksTable
					WHERE	fldtype IN ('Kharid', 'mojodi_ebteda_doreh')--,'bargashtazforoosh')
					Group BY [CodeKala]) DbRemaindCount ON [Stuff].fldCodeKala=DbRemaindCount.CodeKala
WHERE	isnumeric(DbRemain.RemaindCount)=1;


DECLARE StuffCursor Cursor For
SELECT	DISTINCT [CodeKala],RemaindCount From @ResultTable

DECLARE @CodeKala BIGINT,@StuffRemaindCount int

Open StuffCursor
FETCH NEXT FROM StuffCursor INTO @CodeKala,@StuffRemaindCount
WHILE @@FETCH_STATUS=0
BEGIN
	
	DECLARE @SellAmountAtEnd Decimal = 0, @fldTedadeJozVorood int,@fldFeeVahed1BadAzTakhfif bigint, @Temp int = 0
	DECLARE @StuffRemaindAtEnd int = 0, @fldtype nvarchar
		
	DECLARE	KardeksCursor Cursor FOR
	SELECT	[CodeKala],[fldTedadeJozVorood],fldFeeVahed1BadAzTakhfif,fldType From	#KardeksTable WHERE [CodeKala]=@CodeKala AND fldtype IN ('Kharid','mojodi_ebteda_doreh') ORDER BY IdOrder DESC

	Open KardeksCursor
	FETCH NEXT FROM KardeksCursor INTO @CodeKala,@fldTedadeJozVorood,@fldFeeVahed1BadAzTakhfif,@fldtype
	WHILE @@FETCH_STATUS=0
	BEGIN
		IF @StuffRemaindCount > 0
		BEGIN
			IF @StuffRemaindCount > @fldTedadeJozVorood
			BEGIN
				SET @SellAmountAtEnd = @SellAmountAtEnd + (@fldTedadeJozVorood * @fldFeeVahed1BadAzTakhfif)
			END
			ELSE
			BEGIN
				SET @SellAmountAtEnd = @SellAmountAtEnd + (@StuffRemaindCount * @fldFeeVahed1BadAzTakhfif)
			END

			SET @StuffRemaindCount = @StuffRemaindCount - @fldTedadeJozVorood
		END

		FETCH NEXT FROM KardeksCursor INTO @CodeKala,@fldTedadeJozVorood,@fldFeeVahed1BadAzTakhfif,@fldtype
	END
	CLOSE KardeksCursor
	DEALLOCATE KardeksCursor

	update @ResultTable set StuffRemaindAtEnd = @StuffRemaindAtEnd, SellAmountAtEnd= @SellAmountAtEnd WHERE [CodeKala]=@CodeKala

	FETCH NEXT FROM StuffCursor INTO @CodeKala,@StuffRemaindCount
END

Close StuffCursor
DEALLOCATE StuffCursor

SELECT	[CodeKala],[CodeGroup], ISNULL(SumBuyAmount,0) SumBuyAmount,ISNULL(SumBuyCount,0) SumBuyCount,
		ISNULL(SumSellAmount,0) SumSellAmount, ISNULL(SumSellCount,0) SumSellCount,
		ISNULL(SumReSellAmount,0) SumReSellAmount, ISNULL(SumReSellCount,0) SumReSellCount,
		--ISNULL(SumBuyCount,0)+ISNULL(SumReSellCount,0)-ISNULL(SumSellCount,0) Temp,
		RemaindCount,RemaindAtEnd, StuffRemaindAtEnd,
		BahayeTamamShodeFifo = ISNULL(SumBuyAmount,0) - ISNULL(SellAmountAtEnd,0),
		Benefit = ISNULL(SumSellAmount,0) - ISNULL(SumReSellAmount,0) - (ISNULL(SumBuyAmount,0) - ISNULL(SellAmountAtEnd,0))
FROM	@ResultTable

DROP Table #KardeksTable

	SET NOCOUNT OFF
END
GO

-- ===============================================
-- SP: [dbo].[SooratHesab]
-- ===============================================
IF OBJECT_ID(N'dbo.SooratHesab', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[SooratHesab] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[SooratHesab]
@fast nvarchar(5),
@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),@ShomareSanadEbteda bigint
	declare @ShomareDaryaft bigint,@ShomarePardakht bigint, @strAlaki nvarchar(50),@lngAlaki bigint,@SharheKol nvarchar(200) ,@lngNaghd bigint,@strMoinKamelSandoogh nvarchar(10),@strSharhenaghd nvarchar(200) ,@lngBank bigint,@lngBank2 bigint,@lngBank3 bigint,@strMoinKamelBank nvarchar(10),@strMoinKamelBank2 nvarchar(10),@strMoinKamelBank3 nvarchar(10),@strShareBank nvarchar(200),@strShareBank2 nvarchar(200),@strShareBank3 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),@CodekolHesabhayePardakhtaniTanzimat nvarchar(10),@strSharheHesab nvarchar(50),@bigBed bigint,@bigBes bigint, @CodeMoinKamelHesabhayePardakhtaniTanzimat  nvarchar(10)	

	CREATE TABLE #tmpSooratHesab2(
	[ID] [nvarchar](20) COLLATE Persian_100_CI_AS  NULL  ,
	[radif] [bigint]  null,
	[shomare] [nvarchar](100) COLLATE Persian_100_CI_AS null  ,
	[fldSanad] [nvarchar](50) COLLATE Persian_100_CI_AS NULL ,
	[fldSharh] [nvarchar](250) COLLATE Persian_100_CI_AS NULL  ,
	[fldRiz] [nvarchar](250) COLLATE Persian_100_CI_AS NULL  ,
	[fldDate] [int] NULL,
	[fldTedad][float] null,
	[fldNameVahed] [nvarchar](100)  COLLATE Persian_100_CI_AS,
	[fldNameVahed2] [nvarchar](100)  COLLATE Persian_100_CI_AS,
	[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) COLLATE Persian_100_CI_AS null  ,
	[fldCodeKarbar] bigint,
	[fldNameKarbar] [nvarchar](25) COLLATE Persian_100_CI_AS NULL ,


	[fldMablagh][bigint] null,
	[fldBedehkar] [decimal](18, 0) NULL,
	[fldBestankar] [decimal](18, 0) NULL,
	[fldMande][bigint] null,
	[fldCodeKol] [nvarchar](50) COLLATE Persian_100_CI_AS NULL ,
	[fldCodeMoin] [nvarchar](50) COLLATE Persian_100_CI_AS NULL ,
	[fldCodeTafzili] [nvarchar](50) COLLATE Persian_100_CI_AS NULL ,
	[fldCodeMarkaz1] [nvarchar](50) COLLATE Persian_100_CI_AS NULL ,
	[fldCodeMarkaz2] [nvarchar](50) COLLATE Persian_100_CI_AS NULL  ,
	[fldRadif] [varchar](50) COLLATE Persian_100_CI_AS NULL  ,
	[fldCodeSharh] [varchar](50) COLLATE Persian_100_CI_AS NULL  ,		
	[fldMoinKamel] [nvarchar](50) COLLATE Persian_100_CI_AS NULL  ,
	[fldCodeNoeTafzili] [nvarchar](50) COLLATE Persian_100_CI_AS NULL  ,
	[fldGhateiMovaghat] [nvarchar](50) COLLATE Persian_100_CI_AS NULL  ,
	[fldGhateiDaem] [nvarchar](50) COLLATE Persian_100_CI_AS NULL ,
	[fldSanadGhadim] [nvarchar](50) COLLATE Persian_100_CI_AS NULL  ,
	[fldShomarePeigiri] [nvarchar](50) COLLATE Persian_100_CI_AS NULL  ,
	[fldMoghayerat] [nvarchar](50) COLLATE Persian_100_CI_AS NULL  ,
	[fldType] [nvarchar](50) COLLATE Persian_100_CI_AS NULL  ,
	[fldVaziat][nvarchar](20) COLLATE Persian_100_CI_AS NULL  ,
	[fldVasete] [nvarchar](50) COLLATE Persian_100_CI_AS NULL  ,
	[fldNameVasete] [nvarchar](250) COLLATE Persian_100_CI_AS NULL

) ON [PRIMARY]
---اسناد مربوط به کدتفصیلی یک به یک بررسی میشه و متناسب با نوع سند تحلیل و گسترش میباشد
			declare @bigDateMinForSanad bigint ,@bigDateMaxForSanad bigint ,@bigCodeKolHazine nvarchar(50),@bigCodeKolDaramad nvarchar(50) ,@bigCodeMoinKharid nvarchar(50),@strStartHazine nvarchar(1),@strStartDaramad nvarchar(1),@sanadCheckDaryaftEbteda bigint,@sanadCheckEbtedaPardakht bigint
		declare @tooleKol as int,@strKolForoosh nvarchar(50),@Asnadepardakhtani nvarchar(50),@Asnadepardaryaftani nvarchar(50),@CodemoinForoosh nvarchar(20),@KolSooratHesab1 nvarchar(6),@KolSooratHesab2 nvarchar(6),@KolSooratHesab3 nvarchar(6)

		set @tooleKol=(Select top(1) fldKol from tblPaye)
		execute codemoinhesab 'foroosh' ,@strKolForoosh output

	set @bigDateMinForSanad=@bigDateMin
	set @bigDateMaxForSanad=@bigDateMax

	execute CodeKolHesab 'hazine',@bigCodeKolHazine output
	execute CodeKolHesab 'daramad',@bigCodeKolDaramad output
	execute CodeMoinHesab 'kharid',@bigCodeMoinKharid output
	execute CodeMoinHesab 'checkpardakhti',@Asnadepardakhtani output
	execute CodeMoinHesab 'foroosh',@CodemoinForoosh output

	set @strStartHazine=substring(Convert(varchar,@bigCodeKolHazine),1,1)
	set @strStartDaramad=substring(Convert(varchar,@bigCodeKolDaramad),1,1)
	execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoinKamelHesabhayePardakhtaniTanzimat output
	execute codemoinhesab 'checkpardakhti' ,@strMoinKamelCheckPardakhti output	
	execute codemoinhesab 'check' ,@Asnadepardaryaftani output
	execute codemoinhesab 'check' ,@strMoinKamelCheckDaryafti output
	execute CodeKolHesab 'kolhesabhayepardakhtani' ,@CodekolHesabhayePardakhtaniTanzimat output

	set @KolSooratHesab1=(select fldMeghdar from tblTanzimateKol where fldtype='kolsoorathesab1')
	set @KolSooratHesab2=(select fldMeghdar from tblTanzimateKol where fldtype='kolsoorathesab2')
	set @KolSooratHesab3=(select fldMeghdar from tblTanzimateKol where fldtype='kolsoorathesab3')

	update tblSodooreSanad set fldType='' where fldType is null



	set @ShomareSanadEbteda=(select fldShomareEftetahie from tblControlPanel)


	set @sanadCheckDaryaftEbteda=(select top(1)fldSanad from tblCheckeDaryafti Where fldShomareDaryaft=0)
	if @sanadCheckDaryaftEbteda is null
		set @sanadCheckDaryaftEbteda=0

	set @sanadCheckEbtedaPardakht=(select top(1)fldSanad from tblCheckePardakhti Where fldShomarePardakht=0)
	if @sanadCheckEbtedaPardakht is null
		set @sanadCheckEbtedaPardakht=0

		--(fldSanad<>@ShomareSanadEbteda and fldMoinKamel<>@strMoinKamelCheckDaryafti) and

		delete #tmpSooratHesab2

		update tblSodooreSanad set fldType='' Where fldtype is null

if @fast='ok'
	begin
		declare @CodeKoleHesabhayeDaryaftani nvarchar(20),@CodeKoleHesabhayePardakhtani nvarchar(20)
		
		execute CodeKolHesab 'kolhesabhayedaryaftani',@CodeKoleHesabhayeDaryaftani output
		execute CodeKolHesab 'kolhesabhayepardakhtani',@CodeKoleHesabhayePardakhtani output
		

		insert into #tmpSooratHesab2 (id,fldCodeTafzili,fldSanad,fldRiz,fldDate,fldBedehkar,fldBestankar,fldCodeKol,fldCodeMoin,fldMoinkamel,fldType)			
		Select  id,fldCodeTafzili,fldSanad,fldSharh,fldDate,fldBedehkar,fldBestankar,fldCodeKol,fldCodeMoin,fldMoinkamel,fldType from tblSodooreSanad With (READCOMMITTED) where ((fldCodeKol=@KolSooratHesab1 or fldCodeKol=@KolSooratHesab2 or fldCodeKol=@KolSooratHesab3) and fldCodeTafzili=@CodeTafzili) or not( fldType='pasecheck') and  fldCodeTafzili=@CodeTafzili and (Convert(dec,fldDate) between @bigDateMinForSanad and @bigDateMaxForSanad) and (fldCodeKol=@CodeKoleHesabhayeDaryaftani or fldCodeKol=@CodeKoleHesabhayePardakhtani)   ORDER BY CONVERT(dec, fldSanad), CONVERT(dec, fldRadif)
                                                                                                        



		--update #tmpSooratHesab2 set fldRiz =fldRiz + ' ' +  tblTafzili.fldSharheTafzili from tblTafzili Where #tmpSooratHesab2.fldCodeTafzili=tblTafzili.fldCodeTafzili

		update #tmpSooratHesab2 set fldSharh='افتتاحیه' Where fldType='eftetahie'
		update #tmpSooratHesab2 set fldSharh='خرید' Where fldType='kharid'
		update #tmpSooratHesab2 set fldSharh='پرداخت' Where fldType='pardakht'
		update #tmpSooratHesab2 set fldSharh='دریافت' Where fldType='daryaft'
		update #tmpSooratHesab2 set fldSharh='برگشت از خرید' Where fldType='bargashtazkharid'
		update #tmpSooratHesab2 set fldSharh='فروش' Where fldType='foroosh'
		update #tmpSooratHesab2 set fldSharh='برگشت از فروش' Where fldType='bargashtazforoosh'

		update #tmpSooratHesab2 set fldriz='دریافت شماره' + ' ' + Convert(varchar,fldShomareDaryaft), shomare=fldShomareDaryaft from tblDaryaft Where #tmpSooratHesab2.fldSanad=tblDaryaft.fldShomareSanad
		update #tmpSooratHesab2 set fldriz='پرداخت شماره' + ' ' + Convert(varchar,fldShomarePardakht), shomare=fldShomarePardakht from tblPardakht Where #tmpSooratHesab2.fldSanad=tblPardakht.fldShomareSanad

		update #tmpSooratHesab2 set fldriz='فاکتور خرید' + ' ' + Convert(varchar,fldShomareFactorKharid),shomare=fldShomareFactorKharid from tblKharid Where #tmpSooratHesab2.fldSanad=tblKharid.fldShomareSanad
		update #tmpSooratHesab2 set fldriz='برگشت از خرید ' + ' ' + Convert(varchar,fldShomareFactorKharid),shomare=fldShomareFactorKharid from tblBargashtAzKharid Where #tmpSooratHesab2.fldSanad=tblBargashtAzKharid.fldShomareSanad

		update #tmpSooratHesab2 set fldriz='فاکتور فروش' + ' ' + Convert(varchar,fldShomareFactorForoosh), shomare=fldShomareFactorforoosh from tblForoosh Where #tmpSooratHesab2.fldSanad=tblForoosh.fldShomareSanad
		update #tmpSooratHesab2 set fldriz='برگشت از فروش' + ' ' + Convert(varchar,fldShomareFactorForoosh), shomare=fldShomareFactorforoosh from tblBargashtAzForoosh Where #tmpSooratHesab2.fldSanad=tblBargashtAzForoosh.fldShomareSanad

		

		if @flagMande =1 --با نقل مانده		
			begin
				declare @decMandeGhablBed decimal(18,0) ,@decMandeGhablBes decimal(18,0) ,@decMandeGhabl decimal(18,0) 

					declare @CodeKol nvarchar(100),@MandeTalab bigint,@MandeBedehi bigint

					execute CodeKolHesab 'kolhesabhayedaryaftani',@CodeKol 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,fldDate)<@bigDateMin)

					

					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,fldDate)<@bigDateMin)
					set @decMandeGhabl=@MandeTalab-@MandeBedehi								
				if @decMandeGhabl<>0
					insert into #tmpSooratHesab2
						(id,shomare,fldSanad,fldSharh,fldDate,fldBedehkar,fldBestankar,fldMande,fldtype)
							values
						('0','','0','مانده قبل',@bigDateMin,@MandeTalab,@MandeBedehi,@decMandeGhabl,'ghabl')
			end 

		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

			--update #tmpSooratHesab2 set id=0

			if @intOrder=0  --مرتب سازی براساس تاریخ
				Select  ID,radif,shomare,fldSanad,fldSharh,fldRiz,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate,fldTedad,fldNameVahed,
					fldNameVahed2,fldFee,fldFeeYekCarton,fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,
					fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,
					fldMablaghKhales,fldCodeAnbar,fldNameAnbar,fldMablagh,fldBedehkar,fldBestankar,fldMande,
					fldType,fldVaziat,fldVasete,fldCodeKarbar,fldNameKarbar  from #tmpSooratHesab2 order by Convert(dec,fldDate),Convert(dec,fldSanad)	


				--select ID,radif,shomare,fldSanad,fldSharh,fldRiz,substring(convert(nvarchar(10),fldDate),0,3) +'/' +substring(convert(nvarchar(10),fldDate),3,2) + '/' + substring(convert(nvarchar(10),fldDate),5,2) as fldDate,fldTedad,fldNameVahed,
				--	fldNameVahed2,fldFee,fldFeeYekCarton,fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,
				--	fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,
				--	fldMablaghKhales,fldCodeAnbar,fldNameAnbar,fldMablagh,fldBedehkar,fldBestankar,fldMande,
				--	fldType,fldVaziat,fldVasete,fldCodeKarbar,fldNameKarbar



			else
				if @intOrder=1  --مرتب سازی براساس سند
					Select  ID,radif,shomare,fldSanad,fldSharh,fldRiz,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate,fldTedad,fldNameVahed,
					fldNameVahed2,fldFee,fldFeeYekCarton,fldFeeKol,fldDarsadTakhfif,fldMablaghTakhfif,
					fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,
					fldMablaghKhales,fldCodeAnbar,fldNameAnbar,fldMablagh,fldBedehkar,fldBestankar,fldMande,
					fldType,fldVaziat,fldVasete,fldCodeKarbar,fldNameKarbar  from #tmpSooratHesab2 order by Convert(dec,fldSanad)	

	end
else
	begin
	--select * from tblsodooresanad where fldsanad=331


		--(fldSanad<>@ShomareSanadEbteda and fldMoinKamel<>@strMoinKamelCheckDaryafti) and
			declare @kolhesabhayepardakhtani nvarchar(50),@kolhesabhayedaryaftani nvarchar(50),@CodeKoleHesabhayeDaryaftani2 nvarchar(20),@CodeKoleHesabhayePardakhtani2 nvarchar(20),@MoinKamel nvarchar(50),@fldCodeKol nvarchar(50),@CodeKoleMoinCheck nvarchar(20)
			execute CodeKolHesab 'kolhesabhayepardakhtani' ,@kolhesabhayepardakhtani output
			execute CodeKolHesab 'kolhesabhayedaryaftani' ,@kolhesabhayedaryaftani output
			execute CodeKolHesab 'check' ,@CodeKoleMoinCheck output
			--Select Id from tblSodooreSanad With (READCOMMITTED) where  (fldType='' and ( (fldType<>'checkebteda')  and  fldCodeTafzili=10015)  ) or  ( (fldType<>'checkebteda') and  fldsanad<>3 and fldSanad<>12 and fldCodeTafzili=10015 )  and  ((fldtype<>'Vosool' and fldtype<>'pasecheck')) and fldType<>'ebteda' and not(fldtype='ekhtetamie') and Not( fldType='eftetahie' and fldMoinKamel=31701)   and Not( fldType='eftetahie' and fldMoinKamel=11701) and Not( fldType='eftetahie' and fldcodekol='811') and fldCodeKol<>612  and fldMoinKamel<>@bigCodeMoinKharid and substring(fldMoinKamel,1,1)<>@strStartHazine and (substring(fldMoinKamel,1,@tooleKol)<>@strStartDaramad or  fldMoinKamel=@strKolForoosh) and (substring(fldMoinKamel,1,1)<>@CodeMoinKamelHesabhayePardakhtaniTanzimat and fldType<>'hazine') and fldMoinKamel<>@CodeKoleMoinCheck) ORDER BY CONVERT(dec, fldSanad), CONVERT(dec, fldRadif)

			declare EmpCursor Cursor For
				--Select Id from tblSodooreSanad With (READCOMMITTED) where not(fldMoinKamel=@strMoinKamelCheckDaryafti and fldtype='dasti') and (fldCodeKol<>@bigCodeKolDaramad) and (fldMoinKamel<> @strMoinKamelCheckPardakhti) and ((fldType='' and ( (fldType<>'checkebteda')  and  fldCodeTafzili=@CodeTafzili )  ) or  ( (fldType<>'checkebteda') and  fldsanad<>@sanadCheckDaryaftEbteda and fldSanad<>@sanadCheckEbtedaPardakht and fldCodeTafzili=@CodeTafzili and (Convert(dec,fldDate) between @bigDateMinForSanad and @bigDateMaxForSanad)  and  ((fldtype<>'Vosool' and fldtype<>'pasecheck')) and fldType<>'ebteda' and not(fldtype='ekhtetamie') and Not( fldType='eftetahie' and fldMoinKamel=@strMoinKamelCheckPardakhti)  and Not( fldType='eftetahie' and fldCodeKol='412')   and Not( fldType='eftetahie' and fldMoinKamel=@strMoinKamelCheckDaryafti) and Not( fldType='eftetahie' and fldcodekol='811') and fldCodeKol<>@bigCodeKolHazine  and fldMoinKamel<>@bigCodeMoinKharid and substring(fldMoinKamel,1,1)<>@strStartHazine and (substring(fldMoinKamel,1,@tooleKol)<>@strStartDaramad or  fldMoinKamel=@strKolForoosh) and (substring(fldMoinKamel,1,1)<>@CodeMoinKamelHesabhayePardakhtaniTanzimat and fldType<>'hazine'))) ORDER BY CONVERT(dec, fldSanad), CONVERT(dec, fldRadif)
				--Select Id from tblSodooreSanad With (READCOMMITTED) where not(fldCodeKol like '7%' and fldtype='dasti') and (((fldCodeKol=@KolSooratHesab1 or fldCodeKol=@KolSooratHesab2 or fldCodeKol=@KolSooratHesab3) and fldCodeTafzili=@CodeTafzili) or not(fldMoinKamel=@strMoinKamelCheckDaryafti and fldtype='dasti') and (fldMoinKamel<> 90101)  and (fldMoinKamel<> @strMoinKamelCheckPardakhti) and ((fldType='' and ( (fldType<>'checkebteda')  and  fldCodeTafzili=@CodeTafzili )  ) or  ( (fldType<>'checkebteda') and  fldsanad<>@sanadCheckDaryaftEbteda and fldSanad<>@sanadCheckEbtedaPardakht and fldCodeTafzili=@CodeTafzili and (Convert(dec,fldDate) between @bigDateMinForSanad and @bigDateMaxForSanad)  and  ((fldtype<>'Vosool' and fldtype<>'pasecheck')) and fldType<>'ebteda' and not(fldtype='ekhtetamie') and Not( fldType='eftetahie' and fldMoinKamel=@strMoinKamelCheckPardakhti)  and Not( fldType='eftetahie' and fldCodeKol='412')   and Not( fldType='eftetahie' and fldMoinKamel=@strMoinKamelCheckDaryafti) and Not( fldType='eftetahie' and fldcodekol='811') and fldCodeKol<>@bigCodeKolHazine  and fldMoinKamel<>@bigCodeMoinKharid and substring(fldMoinKamel,1,1)<>@strStartHazine and (substring(fldMoinKamel,1,@tooleKol)<>@strStartDaramad or  fldMoinKamel=@strKolForoosh) and (substring(fldMoinKamel,1,1)<>@CodeMoinKamelHesabhayePardakhtaniTanzimat and fldType<>'hazine')))) ORDER BY CONVERT(dec, fldSanad), CONVERT(dec, fldRadif)
				--Select Id from tblSodooreSanad With (READCOMMITTED) where not(fldCodeKol in (select fldCodeHesab from tblkolmoin where fldCodeNoeHesab='3') and fldtype='dasti') and (((fldCodeKol=@KolSooratHesab1 or fldCodeKol=@KolSooratHesab2 or fldCodeKol=@KolSooratHesab3) and fldCodeTafzili=@CodeTafzili) or not(fldMoinKamel=@strMoinKamelCheckDaryafti and fldtype='dasti') and (fldMoinKamel<> 90101)  and (fldMoinKamel<> @strMoinKamelCheckPardakhti) and ((fldType='' and ( (fldType<>'checkebteda')  and  fldCodeTafzili=@CodeTafzili )  ) or  ( (fldType<>'checkebteda') and  fldsanad<>@sanadCheckDaryaftEbteda and fldSanad<>@sanadCheckEbtedaPardakht and fldCodeTafzili=@CodeTafzili and (Convert(dec,fldDate) between @bigDateMinForSanad and @bigDateMaxForSanad)  and  ((fldtype<>'Vosool' and fldtype<>'pasecheck')) and fldType<>'ebteda' and not(fldtype='ekhtetamie') and Not( fldType='eftetahie' and fldMoinKamel=@strMoinKamelCheckPardakhti)  and Not( fldType='eftetahie' and fldCodeKol='412')   and Not( fldType='eftetahie' and fldMoinKamel=@strMoinKamelCheckDaryafti) and Not( fldType='eftetahie' and fldcodekol='811') and fldCodeKol<>@bigCodeKolHazine  and fldMoinKamel<>@bigCodeMoinKharid and substring(fldMoinKamel,1,1)<>@strStartHazine and (substring(fldMoinKamel,1,@tooleKol)<>@strStartDaramad or  fldMoinKamel=@strKolForoosh) and (substring(fldMoinKamel,1,1)<>@CodeMoinKamelHesabhayePardakhtaniTanzimat and fldType<>'hazine')))) ORDER BY CONVERT(dec, fldSanad), CONVERT(dec, fldRadif)
					Select Id from tblSodooreSanad With (READCOMMITTED) where fldcodekol<>@bigCodeKolDaramad and  not(fldCodeKol in (SELECT distinct s.fldCodeKol
						FROM tblsodooresanad s
						WHERE EXISTS (
							SELECT 1
							FROM tblkolmoin k
							WHERE (k.fldCodeNoeHesab = '3' or k.fldCodeNoeHesab = '2' or k.fldCodeNoeHesab = '8') and len(fldCodeHesab)=1
							  AND s.fldcodekol LIKE k.fldCodeHesab + '%'
						) ) and fldtype='dasti') 
				and (((fldCodeKol=@KolSooratHesab1 or fldCodeKol=@KolSooratHesab2 or fldCodeKol=@KolSooratHesab3) and fldCodeTafzili=@CodeTafzili) or not(fldMoinKamel=@strMoinKamelCheckDaryafti and fldtype='dasti') and (fldMoinKamel<> 90101)  and (fldMoinKamel<> @strMoinKamelCheckPardakhti) and ((fldType='' and ( (fldType<>'checkebteda')  and  fldCodeTafzili=@CodeTafzili )  ) or  ( (fldType<>'checkebteda') and  fldsanad<>@sanadCheckDaryaftEbteda and fldSanad<>@sanadCheckEbtedaPardakht and fldCodeTafzili=@CodeTafzili and (Convert(dec,fldDate) between @bigDateMinForSanad and @bigDateMaxForSanad)  and  ((fldtype<>'Vosool' and fldtype<>'pasecheck')) and fldType<>'ebteda' and not(fldtype='ekhtetamie') and Not( fldType='eftetahie' and fldMoinKamel=@strMoinKamelCheckPardakhti)  and Not( fldType='eftetahie' and fldCodeKol='412')   and Not( fldType='eftetahie' and fldMoinKamel=@strMoinKamelCheckDaryafti) and Not( fldType='eftetahie' and fldcodekol='811') and fldCodeKol<>@bigCodeKolHazine  and fldMoinKamel<>@bigCodeMoinKharid and substring(fldMoinKamel,1,1)<>@strStartHazine and (substring(fldMoinKamel,1,@tooleKol)<>@strStartDaramad or  fldMoinKamel=@strKolForoosh) and (substring(fldMoinKamel,1,1)<>@CodeMoinKamelHesabhayePardakhtaniTanzimat and fldType<>'hazine')))) 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

							execute CodeKolHesab 'kolhesabhayedaryaftani',@CodeKoleHesabhayeDaryaftani2 output
							execute CodeKolHesab 'kolhesabhayepardakhtani',@CodeKoleHesabhayePardakhtani2 output

							set @type =(Select top(1)fldType from tblSodooresanad Where ID=@EmpId)

							--برای سند دستی که اگر چیزی غیر از حسابهای دریافتنی و پرداختنی بود نمایش نده
							--################################################################################
							if @type=''
								begin
									set @fldCodeKol=(Select fldCodeKol
										from tblSodooreSanad 
											Where ID=Convert(varchar,@EmpId))
									if @fldCodeKol<>@CodeKoleHesabhayeDaryaftani2 and @fldCodeKol<>@CodeKoleHesabhayePardakhtani2
											begin
												set @type=''
											end
										else
											begin
												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)
											end
								end
								--################################################################################
							else
									begin
					
										-- ریختن کلیه اسناد مربوط به تفصیلی در جدول موقت  #########
										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)

									end

												
							set @CodeKolMoin =(Select top(1)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 top(1)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,@codeKarbar bigint,@NameKarbar nvarchar(20)									
											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=' فروش' +case when (fldSharh='' or fldSharh is null) then '' else '-' + fldSharh end   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)

										--اضافه کردن نام کاربر
										 set @codekarbar=	(select top(1) fldCodeKarbar from tblAmalkardekarbar where fldShomare=@ShomareFactor and fldNameForm=N'فروش' and NoeAmaliat=N'جدید' order by id desc)
										 if @codekarbar is not null
											set @namekarbar =(select top(1) fldNameKarbar from tblAmalkardekarbar where fldShomare=@ShomareFactor and fldNameForm=N'فروش' and NoeAmaliat=N'جدید' order by id desc)
										 else
											begin
												set @codekarbar=0
												set @namekarbar =''
											end

										update #tmpSooratHesab2 set fldCodeKarbar = @codeKarbar,fldNameKarbar=@NameKarbar  where fldSanad= @ShomareSanad
											--### حذف ردیف سندی که کد کل و معینش فروشه ، در حقیقت فقط باید حسابهای دریافتنی و پرداختنی و سندهای دستی نمایش داده بشه									
										end


									else if @CodekolMoinHesabhayeDaryaftaniTanzimat = @CodeKolMoin  -- اگر سند مربوط به دریافت در فروش بود
										begin
											set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)									
											set @ShomareSanad=(Select top(1)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
											--execute	ShowDaryaftInfoChandBank @ShomareDaryaft, @str1, @lngAlaki, @lngAlaki2, @SharheKol output, 'daryaft', @lngNaghd  output, @strMoinKamelSandoogh  output, @strSharhenaghd  output, @lngBank  output, @strMoinKamelBank  output, @strShareBank  output, @lngBank2  output, @strMoinKamelBank2  output, @strShareBank2  output, @lngBank3  output, @strMoinKamelBank3  output, @strShareBank3  output, @lngCheck  output, @strSharheCheck  output, @lngTakhfif  output, @strSharheTakhfifat  output, @str2, @str3
											execute	ShowDaryaftInfoChandBank @ShomareDaryaft, @str1, @lngAlaki, @lngAlaki2, @SharheKol output, 'daryaft', @lngNaghd  output, @strMoinKamelSandoogh  output, @strSharhenaghd  output, @lngBank  output, @strMoinKamelBank  output, @strShareBank  output, @lngBank2  output, @strMoinKamelBank2  output, @strShareBank2  output, @lngBank3  output, @strMoinKamelBank3  output, @strShareBank3  output, @lngCheck  output, @strSharheCheck  output, @lngTakhfif  output, @strSharheTakhfifat  output, @str2, @str3

											UPDATE       #tmpSooratHesab2
												SET                fldSharh = @SharheKol
													where #tmpSooratHesab2.ID = @EmpId


									
											update #tmpSooratHesab2
												set fldSharh ='دریافت' +case when @SharheKol='' then '' else ' - ' +@SharheKol end , 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 +case when @strSharhenaghd='' then '' else '-' +@strSharhenaghd end   ,@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 + case when @strShareBank='' then '' else '-' +@strShareBank end   ,@bigDate,@lngBank,'foroosh')
														end
													if @lngBank2>0
														begin
															set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank2)
															insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
																values (Convert(varchar,@EmpId) + '102' ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ش ف' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + case when @strShareBank2='' then '' else '-' +@strShareBank2 end   ,@bigDate,@lngBank2,'foroosh')
														end
													if @lngBank3>0
														begin
															set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank3)
															insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
																values (Convert(varchar,@EmpId) + '102' ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ش ف' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + case when @strShareBank3='' then '' else '-' +@strShareBank3 end   ,@bigDate,@lngBank3,'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) + case when @strSharheCheck='' then '' else '-' +@strSharheCheck end   ,@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 +case when @strSharhenaghd='' then '' else '-' +@strSharhenaghd end  ,@bigDate,@lngTakhfif,'foroosh')
														end
												end
										end

								
								end

					
							set @CodeKolMoin =(Select top(1)fldMoinKamel from tblSodooresanad Where ID=@EmpId)--11301
							set @CodeKolSanad =(Select top(1)fldCodeKol from tblSodooresanad Where ID=@EmpId)--113
							set @CodeKolTanzimat =(Select top(1)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 top(1)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 top(1)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,0, @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=' خرید' +case when fldSharh='' then '' else '-' +fldSharh end   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



										--اضافه کردن نام کاربر
										 set @codekarbar=	(select top(1) fldCodeKarbar from tblAmalkardekarbar where fldShomare=@ShomareFactor and fldNameForm=N'خرید' and NoeAmaliat=N'جدید' order by id desc)
										 if @codekarbar is not null
											set @namekarbar =(select top(1) fldNameKarbar from tblAmalkardekarbar where fldShomare=@ShomareFactor and fldNameForm=N'خرید' and NoeAmaliat=N'جدید' order by id desc)
										 else
											begin
												set @codekarbar=0
												set @namekarbar =''
											end
											update #tmpSooratHesab2 set fldCodeKarbar = @codeKarbar,fldNameKarbar=@NameKarbar  where fldSanad= @ShomareSanad

											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 + case when @strSharhenaghd='' then '' else '-' +@strSharhenaghd end ,@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 + case when @strShareBank='' then '' else '-' +    @strShareBank end,@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) + case when @strSharheCheck='' then '' else '-' +@strSharheCheck end ,@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) + case when @strSCheckVaghozari='' then '' else '-' +@strSCheckVaghozari end ,@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 + case when @strSharheTakhfifat='' then '' else '-' +  @strSharheTakhfifat end  ,@bigDate,@lngTakhfif,'kharid')
														end
												end
										end
								
								end



							execute codemoinhesab 'foroosh' ,@CodekolmoinTanzimat output

					

							--###### برگشت از فروش ##################
							if @type='bargashtazforoosh'   ---برای نمایش ریز برگشت از فروش
								begin
									set @ShomareSanad=(Select top(1)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 top(1)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,0, @str2, @str3


												set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)
												set @ShomareFactor =(Select  fldShomareFactorForoosh from tblBargashtAzForoosh Where fldShomareSanad = @ShomareSanad)

											--اضافه کردن نام کاربر
											 set @codekarbar=	(select top(1) fldCodeKarbar from tblAmalkardekarbar where fldShomare=@ShomareFactor and fldNameForm=N'برگشت از فروش' and NoeAmaliat=N'جدید' order by id desc)
											 if @codekarbar is not null
												set @namekarbar =(select top(1) fldNameKarbar from tblAmalkardekarbar where fldShomare=@ShomareFactor and fldNameForm=N'برگشت از فروش' and NoeAmaliat=N'جدید' order by id desc)
											 else
												begin
													set @codekarbar=0
													set @namekarbar =''
												end
											update #tmpSooratHesab2 set fldCodeKarbar = @codeKarbar,fldNameKarbar=@NameKarbar  where fldSanad= @ShomareSanad
												
												if @bigbes>0  or (@bigbes=0 and @bigbed=0)
													begin
														update #tmpSooratHesab2 set shomare = 'ب ف'+Convert(varchar, @ShomareFactor) ,fldSharh=' برگشت از فروش' + case when fldSharh ='' then '' else '-' +  fldSharh end 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 + case when @strSharhenaghd='' then '' else '-' +@strSharhenaghd end,@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 + case when @strShareBank='' then '' else '-' + @strShareBank end  ,@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) + case when @strSharheCheck='' then '' else '-' +@strSharheCheck end  ,@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) + case when @strSCheckVaghozari='' then '' else '-' +@strSCheckVaghozari end ,@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 + case when @strSharheTakhfifat='' then '' else ' - ' +@strSharheTakhfifat end,@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 top(1)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 ='دریافت' + case when  @SharheKol='' then '' else ' - ' +@SharheKol end ,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 top(1)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
											execute	ShowDaryaftInfoChandBank @ShomareDaryaft, @str1, @lngAlaki, @lngAlaki2, @SharheKol output, 'bargashtazkharid', @lngNaghd  output, @strMoinKamelSandoogh  output, @strSharhenaghd  output, @lngBank  output, @strMoinKamelBank  output, @strShareBank  output, @lngBank2  output, @strMoinKamelBank2  output, @strShareBank2  output, @lngBank3  output, @strMoinKamelBank3  output, @strShareBank3  output, @lngCheck  output, @strSharheCheck  output, @lngTakhfif  output, @strSharheTakhfifat  output, @str2, @str3
											--execute	ShowDaryaftInfoChandBank @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)

											--اضافه کردن نام کاربر
											 set @codekarbar=	(select top(1) fldCodeKarbar from tblAmalkardekarbar where fldShomare=@ShomareFactor and fldNameForm=N'برگشت از خرید' and NoeAmaliat=N'جدید' order by id desc)
											 if @codekarbar is not null
												set @namekarbar =(select top(1) fldNameKarbar from tblAmalkardekarbar where fldShomare=@ShomareFactor and fldNameForm=N'برگشت از خرید' and NoeAmaliat=N'جدید' order by id desc)
											 else
												begin
													set @codekarbar=0
													set @namekarbar =''
												end
											update #tmpSooratHesab2 set fldCodeKarbar = @codeKarbar,fldNameKarbar=@NameKarbar  where fldSanad= @ShomareSanad


									
											if @bigbed>0  or (@bigbes=0 and @bigbed=0)
												begin
													update #tmpSooratHesab2 set shomare = 'ب خ'+Convert(varchar, @ShomareFactor) ,fldSharh=' برگشت از خرید' + case when fldSharh='' then '' else '-' +fldSharh end   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 + case when @strSharhenaghd='' then '' else '-' +@strSharhenaghd end ,@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 + case when @strShareBank='' then '' else '-' +@strShareBank end  ,@bigDate,@lngBank,'bargashtazkharid')
																end
															if @lngBank2>0
																begin
																	set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank2)
																	insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
																		values (Convert(varchar,@EmpId+1) + '102' ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ب خ' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + case when @strShareBank2='' then '' else '-' +@strShareBank2 end  ,@bigDate,@lngBank2,'bargashtazkharid')
																end
															if @lngBank3>0
																begin
																	set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank3)
																	insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
																		values (Convert(varchar,@EmpId+1) + '102' ,'ش د' + Convert(varchar,@ShomareDaryaft) + ' ب خ' + Convert(varchar,@ShomareFactor),@ShomareSanad,@strSharheHesab + case when @strShareBank3='' then '' else '-' +@strShareBank3 end  ,@bigDate,@lngBank3,'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) +  case when @strSharheCheck='' then '' else '-' +@strSharheCheck end  ,@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 + case when @strSharhenaghd='' then '' else '-' +@strSharhenaghd end  ,@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
									execute	ShowDaryaftInfoChandBank @ShomareDaryaft, @str1, @lngAlaki, @lngAlaki2, @SharheKol output, 'bargashtazkharid', @lngNaghd  output, @strMoinKamelSandoogh  output, @strSharhenaghd  output, @lngBank  output, @strMoinKamelBank  output, @strShareBank  output, @lngBank2  output, @strMoinKamelBank2  output, @strShareBank2  output, @lngBank3  output, @strMoinKamelBank3  output, @strShareBank3  output, @lngCheck  output, @strSharheCheck  output, @lngTakhfif  output, @strSharheTakhfifat  output, @str2, @str3

									--اضافه کردن نام کاربر
									set @codekarbar=	(select top(1) fldCodeKarbar from tblAmalkardekarbar where fldShomare=@ShomareDaryaft and fldNameForm='دريافت' and NoeAmaliat='جدید' order by id desc)
									if @codekarbar is not null
									set @namekarbar =(select top(1) fldNameKarbar from tblAmalkardekarbar where fldShomare=@ShomareDaryaft and fldNameForm=N'دريافت' and NoeAmaliat='جدید' order by id desc)
									else
									begin
										set @codekarbar=0
										set @namekarbar =''
									end
									update #tmpSooratHesab2 set fldCodeKarbar = @codeKarbar,fldNameKarbar=@NameKarbar  where fldSanad= @ShomareSanad

									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 + case when @strSharhenaghd='' then '' else '-' +@strSharhenaghd end ,@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 + case when @strShareBank='' then '' else '-' +@strShareBank end ,@bigDate,@lngBank,'daryaft')
											end
											if @lngBank2>0
											begin
												set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank2)
												insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
													values (Convert(varchar,@EmpId)+ '102' ,'ش د' + Convert(varchar,@ShomareDaryaft) ,@ShomareSanad,@strSharheHesab + case when @strShareBank2='' then '' else '-' +@strShareBank2 end ,@bigDate,@lngBank2,'daryaft')
											end

											if @lngBank3>0
											begin
												set @strSharheHesab = (Select fldSharhehesab from tblKolMoin Where fldCodeHesab =@strMoinKamelBank3)
												insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
													values (Convert(varchar,@EmpId)+ '102' ,'ش د' + Convert(varchar,@ShomareDaryaft) ,@ShomareSanad,@strSharheHesab + case when @strShareBank3='' then '' else '-' +@strShareBank3 end ,@bigDate,@lngBank3,'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) +  case when @strSharheCheck='' then '' else '-' +@strSharheCheck end  ,@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 + case when @strSharhenaghd='' then '' else '-' +@strSharhenaghd end  ,@bigDate,@lngTakhfif,'daryaft')
											end
								
										end
								end




							if @type = 'pardakht' or @type = 'pardakhtsayer' or @Type='pardakhtpersonel'  -- اگر سند مربوط به پرداخت اصلی بود
								begin
										set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)									
										set @ShomareSanad=(Select top(1)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,0, @str2, @str3

										--اضافه کردن نام کاربر
										set @codekarbar=	(select top(1) fldCodeKarbar from tblAmalkardekarbar where fldShomare=@ShomarePardakht and fldNameForm='پرداخت' and NoeAmaliat='جدید' order by id desc)
										if @codekarbar is not null
										set @namekarbar =(select top(1) fldNameKarbar from tblAmalkardekarbar where fldShomare=@ShomarePardakht and fldNameForm=N'پرداخت' and NoeAmaliat='جدید' order by id desc)
										else
										begin
											set @codekarbar=0
											set @namekarbar =''
										end
										update #tmpSooratHesab2 set fldCodeKarbar = @codeKarbar,fldNameKarbar=@NameKarbar  where fldSanad= @ShomareSanad


										set @bigDate=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)																	
												
										if @bigbes>0 
											begin
												declare @CheckKolInSanad nvarchar(10)
												set @CheckKolInSanad=(Select fldCodeKol from tblSodooreSanad Where id=@EmpId)

												if @CodeKoleMoinCheck=@CheckKolInSanad 
													delete #tmpSooratHesab2 where id =@EmpId
													--update #tmpSooratHesab2 set fldSharh=@CodeKoleMoinCheck + '  ' +@CheckKolInSanad  where ID=@EmpId
											end
										--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

								--		declare @mmm nvarchar(10)
								--		set @mmm=(select fldMoinKamel from #tmpSooratHesab2 where fldSanad=@ShomareSanad)

								--		delete tblTest5
								--		INSERT INTO dbo.tblTest5
								--				 (name1, name2, name3)
								--					VALUES        (@mmm,@CodeMoinKamelHesabhayePardakhtaniTanzimat,0)

								--select * from tbltest5
											update #tmpSooratHesab2
													set fldVaziat='delete' where fldSanad=@ShomareSanad And (fldcodekol not like @CodekolHesabhayePardakhtaniTanzimat + '%' and fldMoinKamel not like @CodeMoinKamelHesabhayePardakhtaniTanzimat and fldCodeKol<>@KolSooratHesab1 and fldCodeKol<>@KolSooratHesab2 and fldCodeKol<>@KolSooratHesab3)

											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 + case when  @strSharhenaghd='' then '' else '-' +@strSharhenaghd end,@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 + case when  @strShareBank='' then '' else '-' + @strShareBank end  ,@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) ,'cc' + Convert(varchar,@ShomarePardakht) ,@ShomareSanad,'شماره چک ' + Convert(varchar,fldShomareCheck) + ' ' + ' تاریخ ' + Convert(varchar,fldDateSarResid) + case when @strSharheCheck='' then '' else '-' +@strSharheCheck end  ,@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) + case when @strSCheckVaghozari='' then '' else '-' +@strSCheckVaghozari end ,@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 + case when @strSharheTakhfifat='' then '' else ' - ' +@strSharheTakhfifat end ,@bigDate,@lngTakhfif,'pardakht')
												end
								



									end		    
								
								end

								if @type='EbtedaAshkhas'
									begin
										update #tmpSooratHesab2 set fldSharh='طلب ابتدای دوره' + case when fldSharh<>'' and fldSharh is not null then '-' +fldSharh else '' end,fldType='ebtedadore' Where fldBestankar>0 and ID=@EmpId 
										update #tmpSooratHesab2 set fldSharh='بدهی ابتدای دوره' + case when fldSharh<>'' and fldSharh is not null then '-' +fldSharh else '' end,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 + case when fldSharh<>'' and fldSharh is not null then '-' +fldSharh else '' end,fldType='other' Where   ID=@EmpId 
									end
								if @type='amani'
									begin
										declare @ShomareAmani bigint
										declare @bigDate2 bigint									
										set @bigDate2=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)

										set @ShomareAmani =(Select  Top(1)fldShomareAmani from tblRizeForoosh  Where fldShomareSanad = @ShomareSanad)
										update #tmpSooratHesab2 set shomare = 'امانی'+Convert(varchar, @ShomareAmani), fldBedehkar=0, fldSharh='فروش امانی' + case when fldSharh<>'' and fldSharh is not null then '-' +fldSharh else '' end,fldType='amani' Where fldBedehkar>0 and ID=@EmpId 

										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, @ShomareAmani),@ShomareSanad, dbo.tblKala.fldNameKala + ' ' + dbo.tblRizeForoosh.fldSharhKala,
													@bigDate2,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,'amani'
											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.fldShomareAmani = @ShomareAmani)
									end

								if @type='bargashtamani'
									begin
										--declare @ShomareAmani bigint
										--declare @bigDate2 bigint									
										set @bigDate2=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)

										set @ShomareAmani =(Select  Top(1)fldShomareBargashtAmani from tblRizeBargashtAzForoosh  Where fldShomareSanad = @ShomareSanad)
										update #tmpSooratHesab2 set shomare = 'برگشت امانی'+Convert(varchar, @ShomareAmani), fldBestankar=0, fldSharh='برگشت امانی' + case when fldSharh<>'' and fldSharh is not null then '-' +fldSharh else '' end,fldType='bargashtamani' Where fldBestankar>0 and ID=@EmpId 

										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, @ShomareAmani),@ShomareSanad, dbo.tblKala.fldNameKala + ' ' + dbo.tblRizeBargashtAzForoosh.fldSharhKala,
													@bigDate2,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,'bargashtamani'
											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.fldShomareBargashtAmani = @ShomareAmani)
									end

									if @type='checkebteda'
										begin									
											--declare @ShomareAmani bigint
											--declare @bigDate2 bigint									
											set @bigDate2=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)

											--set @ShomareAmani =(Select  Top(1)fldShomareAmani from tblRizeForoosh  Where fldShomareSanad = @ShomareSanad)
											update #tmpSooratHesab2 set fldBedehkar=0,fldBestankar=0, shomare = 'چک دریافتی ابتدای دوره',  fldSharh='چک ابتدای دوره' + case when fldSharh<>'' and fldSharh is not null then '-' +fldSharh else '' end,fldType='checkebteda' Where fldBedehkar>0 and ID=@EmpId 

											insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
												select Convert(varchar,@EmpId)+'103'  + Convert(varchar,id) ,'چک ابتدای دوره'  ,@ShomareSanad,'چک شماره ' + Convert(varchar,fldShomareCheck) + ' تاریخ ' + Convert(varchar,fldDateSarResid) +  case when @strSharheCheck='' then '' else '-' +@strSharheCheck end  ,@bigDate2,fldMablagh,'checkebteda'
												from tblCheckeDaryafti Where fldSanad = @ShomareSanad and fldCodeSahebeCheck=12326

											--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, @ShomareAmani),@ShomareSanad, dbo.tblKala.fldNameKala + ' ' + dbo.tblRizeForoosh.fldSharhKala,
											--			@bigDate2,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,'amani'
											--	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.fldShomareAmani = @ShomareAmani)
										end

							
							if @type='BargashteCheckeVagoz'   ---برگشت چک واگذارشده
								begin									
											declare @ShomarePardakht2 bigint,@CodeTafzili2 nvarchar(10),@SumBed2 bigint,@Bed2 bigint,@ShomareSanad2  bigint,@cnt2 bigint,@ShomareEnteghal bigint,@CodeMoin2 nvarchar(50)
											set @bigDate2=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)
											set @ShomareSanad2=(Select fldSanad from tblSodooresanad Where ID=@EmpId)
											set @CodeTafzili2=(Select fldCodeTafzili from tblSodooresanad Where ID=@EmpId)
											set @SumBed2=(Select Sum(fldBedehkar) as SumBed from tblSodooreSanad Where fldCodeTafzili=@CodeTafzili2 And fldBedehkar>0 and fldSanad=@ShomareSanad2)
											set @Bed2=(Select top(1)fldBedehkar from tblSodooreSanad Where ID=@EmpId)
											set @ShomareEnteghal=(Select top(1)fldShomareEnteghal from tblCheckeDaryafti Where fldShomareSanadEnteghal=@ShomareSanad2)
											execute CodeMoinHesab 'check',@codemoin2 output
											--insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
											--			values ( 999 ,'621'  ,132,'345',990205,111,'dfg')

											--set  @cnt2=(Select count(fldCodeTafzili) from tblTafzili Where fldCodeTafzili=@CodeTafzili2 and ID<@EmpId )
											--if @cnt2=0
											--	begin
													if @Bed2>0 
														begin																
															set @ShomarePardakht2=(Select top(1)fldShomarePardakht from tblCheckeDaryafti Where fldShomareSanadEnteghal=@ShomareSanad2)
									

															--update #tmpSooratHesab2 set  fldBestankar=6666, shomare =@ShomareEnteghal,  fldSharh='' + case when fldSharh<>'' and fldSharh is not null then ' ' +fldSharh else '' end,fldType='BargashteCheckeVagozarShode' Where fldBedehkar>0 and ID=@EmpId 

															--insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
															--	select Convert(varchar,@EmpId)+'103' ,'bbb'  ,@ShomareSanad2,'چک شماره ' + Convert(varchar,fldShomareCheck) + ' تاریخ ' + Convert(varchar,fldDateSarResid)   ,@bigDate2,fldMablagh,'BargashteCheckeVagozarShode'
															--	from tblCheckeDaryafti Where fldShomareSanadEnteghal = @ShomareSanad2 and  fldShomarePardakht=21
															--update #tmpSooratHesab2 set shomare =34 Where id=@EmpId --and fldMoinKamel <> @codemoin2 and fldCodeTafzili=@CodeTafzili2

															update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad2 and fldMoinKamel = @codemoin2 and fldCodeTafzili=@CodeTafzili2
														end
													else
														begin
															update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad2 and fldMoinKamel = @codemoin2 and fldCodeTafzili=@CodeTafzili2
															update #tmpSooratHesab2 set shomare =@ShomareEnteghal Where id=@EmpId --and fldMoinKamel <> @codemoin2 and fldCodeTafzili=@CodeTafzili2
														end 

											--	end
											--else
											--	update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad2 and fldMoinKamel = '31301' and fldCodeTafzili=@CodeTafzili2
												--set @ShomarePardakht2=(Select top(1)fldShomarePardakht from tblCheckeDaryafti Where fldShomareCheck)
												--set @ShomarePardakht2=(select fldCodeTafzili from tblPardakht where fldShomarePardakht=@ShomarePardakht2)

										
												--select * from tblCheckeDaryafti Where fldShomareSanadEnteghal = 132

								end

						

								if @type='OdateCheck'   ---عودت چک فروخته شده
									begin									
												declare @ShomarePardakht3 bigint,@CodeTafzili3 nvarchar(10),@SumBed3 bigint,@BeS3 bigint,@ShomareSanad3  bigint,@cnt3 bigint,@ShomareEnteghal3 bigint,@CodeMoin3 nvarchar(50)
												set @bigDate2=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)
												set @ShomareSanad3=(Select fldSanad from tblSodooresanad Where ID=@EmpId)
												set @CodeTafzili3=(Select fldCodeTafzili from tblSodooresanad Where ID=@EmpId)
												set @SumBed3=(Select Sum(fldBedehkar) as SumBed from tblSodooreSanad Where fldCodeTafzili=@CodeTafzili3 And fldBedehkar>0 and fldSanad=@ShomareSanad3)
												set @BeS3=(Select top(1)fldBestankar from tblSodooreSanad Where ID=@EmpId)
												set @ShomareEnteghal=(Select top(1)fldShomareOdat from tblCheckeDaryafti Where fldShomareSanadOdat=@ShomareSanad3)
												execute CodeMoinHesab 'check',@codemoin3 output
												--insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
												--			values ( 999 ,'621'  ,132,'345',990205,111,'dfg')

												--set  @cnt2=(Select count(fldCodeTafzili) from tblTafzili Where fldCodeTafzili=@CodeTafzili2 and ID<@EmpId )
												--if @cnt2=0
												--	begin
														if @BeS3>0 
															begin																
																set @ShomarePardakht3=(Select top(1)fldShomarePardakht from tblCheckeDaryafti Where fldShomareSanadEnteghal=@ShomareSanad3)
									

																update #tmpSooratHesab2 set   shomare =@ShomareEnteghal,  fldSharh='' + case when fldSharh<>'' and fldSharh is not null then ' ' +fldSharh else '' end,fldType='OdateCheck' Where fldBedehkar>0 and ID=@EmpId 

																--insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
																--	select Convert(varchar,@EmpId)+'103' ,'bbb'  ,@ShomareSanad2,'چک شماره ' + Convert(varchar,fldShomareCheck) + ' تاریخ ' + Convert(varchar,fldDateSarResid)   ,@bigDate2,fldMablagh,'BargashteCheckeVagozarShode'
																--	from tblCheckeDaryafti Where fldShomareSanadEnteghal = @ShomareSanad2 and  fldShomarePardakht=21

																update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad3 and fldMoinKamel = @codemoin3 and fldCodeTafzili=@CodeTafzili3
															end
														else
															begin
																update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad3 and fldMoinKamel = @codemoin3 and fldCodeTafzili=@CodeTafzili3
																update #tmpSooratHesab2 set shomare =@ShomareEnteghal Where id=@EmpId 
															end

												--	end
												--else
												--	update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad2 and fldMoinKamel = '31301' and fldCodeTafzili=@CodeTafzili2
													--set @ShomarePardakht2=(Select top(1)fldShomarePardakht from tblCheckeDaryafti Where fldShomareCheck)
													--set @ShomarePardakht2=(select fldCodeTafzili from tblPardakht where fldShomarePardakht=@ShomarePardakht2)

										
													--select * from tblCheckeDaryafti Where fldShomareSanadEnteghal = 132

									end


									if @Type='bazpascheckekhodeman'  --بازپسگیری چک خود
									begin									
												declare @ShomarePardakht4 bigint,@CodeTafzili4 nvarchar(10),@SumBed4 bigint,@Bed4 bigint,@ShomareSanad4  bigint,@CodeMoin4 nvarchar(50)
												set @bigDate2=(Select Convert(bigint,flddate) from tblSodooresanad Where ID=@EmpId)
												set @ShomareSanad4=(Select fldSanad from tblSodooresanad Where ID=@EmpId)
												set @CodeTafzili4=(Select fldCodeTafzili from tblSodooresanad Where ID=@EmpId)
												set @SumBed4=(Select Sum(fldBedehkar) as SumBed from tblSodooreSanad Where fldCodeTafzili=@CodeTafzili4 And fldBedehkar>0 and fldSanad=@ShomareSanad4)
												set @Bed4=(Select top(1)fldBedehkar from tblSodooreSanad Where ID=@EmpId)
												set @ShomareEnteghal=(Select top(1)fldShomareOdat from tblCheckeDaryafti Where fldShomareSanadOdat=@ShomareSanad4)
												execute CodeMoinHesab 'checkpardakhti',@codemoin4 output

												if @Bed4>0 
													begin																
														set @ShomarePardakht4=(Select top(1)fldShomarePardakht from tblCheckeDaryafti Where fldShomareSanadEnteghal=@ShomareSanad4)
									

														update #tmpSooratHesab2 set   shomare =@ShomareEnteghal,  fldSharh='' + case when fldSharh<>'' and fldSharh is not null then ' ' +fldSharh else '' end,fldType='OdateCheck' Where fldBedehkar>0 and ID=@EmpId 

														update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad3 and fldMoinKamel = @codemoin4 and fldCodeTafzili=@CodeTafzili4
													end
												else
													begin
														update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad4 and fldMoinKamel = @codemoin4 and fldCodeTafzili=@CodeTafzili4
														update #tmpSooratHesab2 set shomare =@ShomareEnteghal Where id=@EmpId 
													end

									end


									if @type='' --سند دستی
										begin --پاک کردن اسناد دستی که ربطی به حسابهای دریافتنی و پرداختنی ندارن
											declare @CodeKol4 nvarchar(20),@ShomareSanad5 nvarchar(20)
											set @CodeKol4=(Select top(1) fldCodeKol  from tblSodooreSanad Where ID=@EmpId)
											set @ShomareSanad5=(Select top(1) fldSanad  from tblSodooreSanad Where ID=@EmpId)
											if @CodeKol4<>@kolhesabhayedaryaftani
												if @CodeKol4<>@kolhesabhayepardakhtani
													update #tmpSooratHesab2 set fldVaziat='delete' Where fldSanad= @ShomareSanad5 and fldCodeKol = @CodeKol4
										end

									--if @type='ekhtetamie'
									--	begin
									--		update #tmpSooratHesab2
									--				set fldVaziat='delete' where fldSanad=@ShomareSanad And fldMoinKamel= @strMoinKamelCheckDaryafti 
									--	end
									--if @type='eftetahie'
									--	begin
									--		update #tmpSooratHesab2
									--				set fldVaziat='delete' where fldSanad=@ShomareSanad And fldMoinKamel= @strMoinKamelCheckDaryafti 
									--	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



		  execute codemoinhesab 'hesabhayedaryaftani' ,@CodekolMoinDaryaftTanzimat output	

			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 fldCodeTafzili=@CodeTafzili and fldMoinKamel=@CodekolMoinDaryaftTanzimat and fldType='ebteda'

			--رکوردهایی که در پایان باید حذف بشن
			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
			delete #tmpSooratHesab2  Where Convert(dec,fldDate)>@bigDateMax
	
			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,fldtype)
				--			values
				--		('0','','0','مانده قبل','0',@SumBedGhabl,@SumBesGhabl,@SumBedGhabl-@SumBesGhabl,'ghabl')
				begin

						declare @CodeKol2 nvarchar(100),@MandeTalab2 bigint,@MandeBedehi2 bigint

						execute CodeKolHesab 'kolhesabhayedaryaftani',@CodeKol2 output

						set @MandeTalab2=(SELECT       ISNULL( SUM(ISNULL(fldBedehkar, 0)-ISNULL(fldBestankar, 0)),0) AS SumM
							FROM            tblSodooreSanad
							WHERE      (fldCodeKol=@CodeKol2) and  (fldCodeTafzili = @CodeTafzili ) and Convert(bigint,fldDate)<@bigDateMin)

					

						execute CodeKolHesab 'kolhesabhayepardakhtani',@CodeKol2 output

						set @MandeBedehi2=(SELECT       ISNULL( SUM(ISNULL(fldBestankar, 0)-ISNULL(fldBedehkar, 0)),0) AS SumM
							FROM            tblSodooreSanad
							WHERE      (fldCodeKol=@CodeKol2) and  (fldCodeTafzili = @CodeTafzili ) and Convert(bigint,fldDate)<@bigDateMin)
						set @decMandeGhabl=@MandeTalab2-@MandeBedehi2								
					if @decMandeGhabl<>0
						insert into #tmpSooratHesab2
							(id,shomare,fldSanad,fldSharh,fldDate,fldBedehkar,fldBestankar,fldMande,fldtype)
								values
							('0','','0','مانده قبل',@bigDateMin,@MandeTalab2,@MandeBedehi2,@decMandeGhabl,'ghabl')
				end 


			--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)

			--update  #tmpSooratHesab2 set flddate=substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2)
			delete from #tmpSooratHesab2 where fldSanad in (Select fldSanadPas from tblCheckePardakhti Where fldCodeSahebeCheck=@CodeTafzili )
	
			declare @MaxId bigint
			set @Maxid =(Select Max(Convert(dec,Id)) as MaxId from #tmpSooratHesab2)
			if isnumeric(@maxId)=0
				set @maxId=1
			else
				set @maxId=@maxId+1



			--set @MaxId=1000
			insert into #tmpSooratHesab2 (id,shomare,fldSanad,fldRiz,fldDate,fldMablaghKhales,fldType)
					Select Convert(varchar,@MaxId),'برگشت چک' ,'0','برگشت چک به شماره '  + Convert(varchar,fldShomareCheck),Convert(varchar,fldDateBargasht),fldMablagh,'bargasht' 
						FROM tblCheckeDaryafti
						Where fldVaziat='Bargasht' and fldCodeSahebeCheck=@CodeTafzili
			
					--values ('2000' ,'ش برگشت' ,'',''  ,0,0,'bargasht')
						--values (Convert(varchar,@EmpId) + '200' ,'ش برگشت' + Convert(varchar,@ShomarePardakht) ,@ShomareSanad,@strSharheHesab + case when  @strShareBank='' then '' else '-' + @strShareBank end  ,@bigDate,@lngBank,'pardakht')

			update #tmpSooratHesab2 set fldnamevasete = tblTafzili.fldSharheTafzili from tblTafzili where #tmpSooratHesab2.fldVasete=tblTafzili.fldCodeTafzili
			
			if @intOrder=0  --مرتب سازی براساس تاریخ
				select radif,shomare,fldSanad,fldSharh,fldRiz,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate,fldTedad,
						fldFee,fldMablaghKhales,fldBedehkar,fldBestankar,fldMande,fldnamevasete,fldNameAnbar,fldType,fldNameKarbar,
						fldNameVahed,fldNameVahed2,fldFeeYekCarton,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,
						fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablagh,fldfeekol,fldVasete,
						fldVaziat,fldCodeAnbar,fldCodeKarbar,id
				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 radif,shomare,fldSanad,fldSharh,fldRiz,substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate,fldTedad,
						fldFee,fldMablaghKhales,fldBedehkar,fldBestankar,fldMande,fldnamevasete,fldNameAnbar,fldType,fldNameKarbar,
						fldNameVahed,fldNameVahed2,fldFeeYekCarton,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,
						fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldFeeKolBadAzTakhfif,fldMablagh,fldfeekol,fldVasete,
						fldVaziat,fldCodeAnbar,fldCodeKarbar,id
					from #tmpSooratHesab2  order by Convert(dec,fldSanad),Convert(varchar,id)

	end
end
GO

-- ===============================================
-- SP: [dbo].[SooratHesab22]
-- ===============================================
IF OBJECT_ID(N'dbo.SooratHesab22', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[SooratHesab22] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[sp_Ttac_GetAllEvents]
-- ===============================================
IF OBJECT_ID(N'dbo.sp_Ttac_GetAllEvents', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[sp_Ttac_GetAllEvents] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[sp_Ttac_GetAllEvents]
(
    @EventType INT = 0,      -- 0 = همه
    @FromDate BIGINT = NULL,
    @ToDate BIGINT = NULL,
    @SyncStatus TINYINT = 9  -- 9 = همه، 0=ارسال‌نشده، 1=ارسال‌شده
)
AS
BEGIN
    SET NOCOUNT ON;

    CREATE TABLE #Events
    (
		
        EventType INT,
        EventTypeName NVARCHAR(50),

        RecordID BIGINT,

        DocumentNumber NVARCHAR(50),
        DocumentDate DATE,
		DateShamsi NVARCHAR(50),

        CodeKala BIGINT,
        Qty DECIMAL(18,2),

        BatchNo NVARCHAR(50),
        IRC NVARCHAR(50),
        GTIN NVARCHAR(50),

        MakeDate DATE NULL,
        ExpDate DATE NULL,

        SourceAnbar BIGINT NULL,
        DestAnbar BIGINT NULL,

        SyncStatus TINYINT,
        RowSource NVARCHAR(50),
		EventID NVARCHAR(50)
    );

    -------------------------------------------------------
    -- 1) فروش
    -------------------------------------------------------
    IF (@EventType = 0 OR @EventType = 1)
    BEGIN
        INSERT INTO #Events
        SELECT 
            1, N'فروش',
            p.ID,
            p.FactorNumber, p.FactorDateMiladi,
			SUBSTRING(CONVERT(nvarchar,p.FactorDateShamsi), 1, 4) + '/' +
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 5, 2) + '/' + 
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 7, 2) AS FactorDateShamsi,
            p.CodeKala,
            p.QtyTotalBase,
            p.BatchNo, p.IRC, p.GTIN,
            p.MakeDateMiladi, p.ExpireDateMiladi,
            p.SourceAnbar, p.DestAnbar,
            p.SyncStatus,
            N'Sales',
			p.EventID
        FROM dbo.tblTtacPendingForoosh p
       
        WHERE (@SyncStatus = 9 OR p.SyncStatus = @SyncStatus)
          AND (@FromDate IS NULL OR p.FactorDateShamsi >= @FromDate)
          AND (@ToDate IS NULL OR p.FactorDateShamsi <= @ToDate);
    END

    -------------------------------------------------------
    -- 2) برگشت از فروش
    -------------------------------------------------------
    IF (@EventType = 0 OR @EventType = 2)
    BEGIN
        INSERT INTO #Events
        SELECT 
            2, N'برگشت از فروش',
            p.ID,
            p.FactorNumber, p.FactorDateMiladi,SUBSTRING(CONVERT(nvarchar,p.FactorDateShamsi), 1, 4) + '/' +
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 5, 2) + '/' + 
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 7, 2) AS FactorDateShamsi,
            p.CodeKala,
            p.QtyTotalBase,
            p.BatchNo, p.IRC, p.GTIN,
             p.MakeDateMiladi, p.ExpireDateMiladi,
            p.SourceAnbar, p.DestAnbar,
            p.SyncStatus,
            N'Return',
			p.EventID
        FROM dbo.tblTtacPendingBargashtAzForoosh p
        WHERE (@SyncStatus = 9 OR p.SyncStatus = @SyncStatus)
          AND (@FromDate IS NULL OR p.FactorDateShamsi >= @FromDate)
          AND (@ToDate IS NULL OR p.FactorDateShamsi <= @ToDate);
    END

    -------------------------------------------------------
    -- 3) خرید
    -------------------------------------------------------
    IF (@EventType = 0 OR @EventType = 3)
    BEGIN
        INSERT INTO #Events
        SELECT 
            3, N'خرید',
            p.ID,
            p.FactorNumber, p.FactorDateMiladi,SUBSTRING(CONVERT(nvarchar,p.FactorDateShamsi), 1, 4) + '/' +
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 5, 2) + '/' + 
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 7, 2) AS FactorDateShamsi,
            p.CodeKala,
            p.QtyTotalBase,
            p.BatchNo, p.IRC, p.GTIN,
             p.MakeDateMiladi, p.ExpireDateMiladi,
            p.SourceAnbar, p.DestAnbar,
            p.SyncStatus,
            N'Purchase',
			p.EventID
        FROM dbo.tblTtacPendingKharid p
        WHERE (@SyncStatus = 9 OR p.SyncStatus = @SyncStatus)
          AND (@FromDate IS NULL OR p.FactorDateShamsi >= @FromDate)
          AND (@ToDate IS NULL OR p.FactorDateShamsi <= @ToDate);
    END

	    -------------------------------------------------------
    -- 4) برگشت از خرید
    -------------------------------------------------------
    IF (@EventType = 0 OR @EventType = 4)
    BEGIN
        INSERT INTO #Events
        SELECT 
            4, N'برگشت از خرید',
            p.ID,
            p.FactorNumber, p.FactorDateMiladi,SUBSTRING(CONVERT(nvarchar,p.FactorDateShamsi), 1, 4) + '/' +
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 5, 2) + '/' + 
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 7, 2) AS FactorDateShamsi,
            p.CodeKala,
            p.QtyTotalBase,
            p.BatchNo, p.IRC, p.GTIN,
             p.MakeDateMiladi, p.ExpireDateMiladi,
            p.SourceAnbar, p.DestAnbar,
            p.SyncStatus,
            N'PurchaseReturn',
			p.EventID
        FROM dbo.tblTtacPendingBargashtAzKharid p
        WHERE (@SyncStatus = 9 OR p.SyncStatus = @SyncStatus)
          AND (@FromDate IS NULL OR p.FactorDateShamsi >= @FromDate)
          AND (@ToDate IS NULL OR p.FactorDateShamsi <= @ToDate);
    END

	    -------------------------------------------------------
    -- 5) فروش امانی
    -------------------------------------------------------
    IF (@EventType = 0 OR @EventType = 5)
    BEGIN
        INSERT INTO #Events
        SELECT
            5, N'فروش امانی',
            p.ID,
            p.FactorNumber, p.FactorDateMiladi,SUBSTRING(CONVERT(nvarchar,p.FactorDateShamsi), 1, 4) + '/' +
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 5, 2) + '/' + 
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 7, 2) AS FactorDateShamsi,
            p.CodeKala,
            p.QtyTotalBase,
            p.BatchNo, p.IRC, p.GTIN,
			NULL, p.ExpireDateMiladi,
            p.SourceAnbar, p.DestAnbar,
            p.SyncStatus,
            N'ForooshAmani',
			p.EventID
        FROM dbo.tblTtacPendingForooshAmani p
        WHERE (@SyncStatus = 9 OR p.SyncStatus = @SyncStatus)
          AND (@FromDate IS NULL OR p.FactorDateShamsi >= @FromDate)
          AND (@ToDate IS NULL OR p.FactorDateShamsi <= @ToDate);
    END

    -------------------------------------------------------
    -- 6) برگشت از فروش امانی
    -------------------------------------------------------
    IF (@EventType = 0 OR @EventType = 6)
    BEGIN
        INSERT INTO #Events
        SELECT
            6, N'برگشت از فروش امانی',
            p.ID,
            p.FactorNumber, p.FactorDateMiladi,SUBSTRING(CONVERT(nvarchar,p.FactorDateShamsi), 1, 4) + '/' +
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 5, 2) + '/' + 
			SUBSTRING(CONVERT(nvarchar, p.FactorDateShamsi), 7, 2) AS FactorDateShamsi,
            p.CodeKala,
            p.QtyTotalBase,
            p.BatchNo, p.IRC, p.GTIN,
            p.MakeDateMiladi, p.ExpireDateMiladi,
            p.SourceAnbar, p.DestAnbar,
            p.SyncStatus,
            N'ForooshAmaniReturn',
			p.EventID
        FROM dbo.tblTtacPendingBargashtAzForooshAmani p
        WHERE (@SyncStatus = 9 OR p.SyncStatus = @SyncStatus)
          AND (@FromDate IS NULL OR p.FactorDateShamsi >= @FromDate)
          AND (@ToDate IS NULL OR p.FactorDateShamsi <= @ToDate);
    END

    -------------------------------------------------------
    -- 7) انتقال بین انبار
    -------------------------------------------------------
    IF (@EventType = 0 OR @EventType = 7)
    BEGIN
        INSERT INTO #Events
        SELECT
            7, N'انتقال بین انبار',
            p.ID,
            p.TransferNumber, p.TransferDateMiladi,'0',
            p.CodeKala,
            p.QtyJoz,
            p.BatchNo, p.IRC, p.GTIN,
            kt.MakeDate, p.ExpireDateMiladi,
            p.SourceAnbar, p.DestAnbar,
            p.SyncStatus,
            N'Transfer',
			p.EventID
        FROM dbo.tblTtacPendingEnteghalKalaAnbar p
        LEFT JOIN dbo.tblKalaTtac kt ON kt.fldCodeKala = p.CodeKala
        WHERE (@SyncStatus = 9 OR p.SyncStatus = @SyncStatus)
          --AND (@FromDate IS NULL OR p.TransferDateMiladi >= @FromDate)
          --AND (@ToDate IS NULL OR p.TransferDateMiladi <= @ToDate);
    END

	    -------------------------------------------------------
    -- 8) حواله گروهی
    -------------------------------------------------------
    IF (@EventType = 0 OR @EventType = 8)
    BEGIN
        INSERT INTO #Events
        SELECT
            8, N'حواله گروهی',
            p.ID,
            p.HavaleNumber, p.HavaleDateMiladi,0,
            p.CodeKala,
            p.QtyTotalBase,
            p.BatchNo, p.IRC, p.GTIN,
            kt.MakeDate, p.ExpireDateMiladi,
            p.SourceAnbar, p.DestAnbar,
            p.SyncStatus,
            N'HavaleGroup',
			p.EventID
        FROM dbo.tblTtacPendingHavaleGroup p
        LEFT JOIN dbo.tblKalaTtac kt ON kt.fldCodeKala = p.CodeKala
        WHERE (@SyncStatus = 9 OR p.SyncStatus = @SyncStatus)
          --AND (@FromDate IS NULL OR p.HavaleDateMiladi >= @FromDate)
          --AND (@ToDate IS NULL OR p.HavaleDateMiladi <= @ToDate);
    END

    -------------------------------------------------------
    -- 9) تولید (MakeDate از خود جدول)
    -------------------------------------------------------
    IF (@EventType = 0 OR @EventType = 9)
    BEGIN
        INSERT INTO #Events
        SELECT
            9, N'تولید',
            p.ID,
            p.ProduceNumber, p.ProduceDateMiladi,'',
            p.CodeKala,
            p.QtyJoz,
            p.BatchNo, p.IRC, p.GTIN,
            p.MakeDate, p.ExpireDateMiladi,
            NULL, NULL,
            p.SyncStatus,
            N'Produce',
			p.EventID
        FROM dbo.tblTtacPendingTolid p
        WHERE (@SyncStatus = 9 OR p.SyncStatus = @SyncStatus)
          --AND (@FromDate IS NULL OR p.ProduceDateMiladi >= @FromDate)
          --AND (@ToDate IS NULL OR p.ProduceDateMiladi <= @ToDate);
    END

		    -------------------------------------------------------
    -- 10) موجودی ابتدای دوره انبار (MakeDate از خود جدول)
    -------------------------------------------------------
    IF (@EventType = 0 OR @EventType = 10)
    BEGIN
        INSERT INTO #Events
        SELECT
            10, N'موجودی ابتدای دوره انبار',
            p.ID,
            p.ShomareSanad, p.DateMiladi,SUBSTRING(CONVERT(nvarchar,p.DateShamsi), 1, 4) + '/' +
			SUBSTRING(CONVERT(nvarchar, p.DateShamsi), 5, 2) + '/' + 
			SUBSTRING(CONVERT(nvarchar, p.DateShamsi), 7, 2) AS FactorDateShamsi,
            p.CodeKala,
            p.QtyJoz,
            p.BatchNo, p.IRC, p.GTIN,
            p.MakeDateMiladi, p.ExpireDateMiladi,
            p.SourceAnbar, NULL,
            p.SyncStatus,
            N'ebteda',
			p.EventID
        FROM dbo.tblTtacPendingMojodiEbteda p
        WHERE (@SyncStatus = 9 OR p.SyncStatus = @SyncStatus)
          AND (@FromDate IS NULL OR p.DateShamsi >= @FromDate)
         AND (@ToDate IS NULL OR p.DateShamsi <= @ToDate);
    END





    -------------------------------------------------------
    -- خروجی نهایی
    -------------------------------------------------------
  	if @EventType=0
    SELECT *
    FROM #Events
    ORDER BY RecordID;
	else
	 SELECT *
    FROM #Events
	where EventType=@EventType
    ORDER BY RecordID;
END
GO

-- ===============================================
-- SP: [dbo].[spEmpDetails]
-- ===============================================
IF OBJECT_ID(N'dbo.spEmpDetails', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[spEmpDetails] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[spTable]
-- ===============================================
IF OBJECT_ID(N'dbo.spTable', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[spTable] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[spTable]
@tbl tbl1 Readonly

as

begin

	insert into tbltest6
		select * from @tbl
end
GO

-- ===============================================
-- SP: [dbo].[TableAmalkardekarbar]
-- ===============================================
IF OBJECT_ID(N'dbo.TableAmalkardekarbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TableAmalkardekarbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[TableAmalkardekarbar]

@Shomare bigint,
@NameForm nvarchar(30),
@NoeAmaliat nvarchar(30)
as 

begin

	SELECT        TOP (200) id, fldCodeKarbar, fldNameKarbar, fldNameForm, NoeAmaliat, fldDate, fldTime, fldShomare, fldSanad
			FROM            tblAmalkardekarbar Where fldShomare=@Shomare And fldNameForm =@NameForm and NoeAmaliat=@NoeAmaliat
	
end
GO

-- ===============================================
-- SP: [dbo].[TableDaftarche]
-- ===============================================
IF OBJECT_ID(N'dbo.TableDaftarche', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TableDaftarche] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[TableDaftarche]

@CodeTafzili nvarchar(10)
as 

begin

	SELECT       fldIdDaftarche, fldCodeTafzili, fldName, fldShomare, fldSms, fldSharh, fldDateUpdate
		FROM            tblDaftarcheTell where fldCodeTafzili=@CodeTafzili 
	
end
GO

-- ===============================================
-- SP: [dbo].[tableDaryaft]
-- ===============================================
IF OBJECT_ID(N'dbo.tableDaryaft', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[tableDaryaft] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[tableDaryaft]

@ShomareSanad bigint
as 

begin

	SELECT       ID, fldShomareDaryaft, fldShomareSanad, fldCodeTafzili, fldType, fldDateUpdate, fldLock
			FROM            tblDaryaft where fldShomareSanad=@ShomareSanad
	
end
GO

-- ===============================================
-- SP: [dbo].[TableForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.TableForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TableForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[TableForoosh]

@ShomareFactor bigint
as 

begin

	SELECT        ID, fldShomareFactorForoosh, fldShomareSanad, fldDate, fldSharhFactor, fldShomareFactorForooshOld, fldLock, fldShomarePishFactor, 
                         fldCodeFeeDynamic, fldDateUpdate, fldRefrenceMoadian, fldTaeidMoadian, fldRefrenceMoadianAsli, fldTaeidMoadianAsli, fldsendweb, fldShomareMaliati, 
                         fldShomareGharardad, fldShenaseMaliatiFactor
FROM            tblForoosh where fldShomareFactorForoosh=@ShomareFactor
	
end
GO

-- ===============================================
-- SP: [dbo].[TableRizeForooshes]
-- ===============================================
IF OBJECT_ID(N'dbo.TableRizeForooshes', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TableRizeForooshes] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[TableRizeForooshes]

@ShomareFactor bigint
as 

begin

	SELECT        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, fldDateEngheza, 
                         fldShomareAmani, fldDateUpdate, fldEshantion, fldGhymatMasrafkonande, fldCodeVasete2, fldCodeMasterEshantion
		FROM            tblRizeForoosh
			where fldShomareFactor=@ShomareFactor
	
end
GO

-- ===============================================
-- SP: [dbo].[TableSodooreSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.TableSodooreSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TableSodooreSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[TableSodooreSanad]

@ShomareSanad nvarchar(50)
as 

begin

	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, fldDateUpdate, fldColorBank, fldColorSandoogh, fldColorSooratHesab
	FROM            tblSodooreSanad
		where fldSanad=@ShomareSanad
	
end
GO

-- ===============================================
-- SP: [dbo].[TableTafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.TableTafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TableTafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[TableTafzili]

@CodeTafzili nvarchar(10)
as 

begin

	SELECT      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, fldNoePersonel, fldVaziatMiz, fldCodeTafziliBigInt, fldDateUpdate, fldbirthdate, fldfathername, fldbirthplace, 
                         flddescription, fldTel, fldDarsadtakhfif, fldHaghighi, fldName, fldUnActive, fldNoeSooratMoadian
		FROM            tblTafzili Where fldCodeTafzili=@CodeTafzili
	
end
GO

-- ===============================================
-- SP: [dbo].[Tabletasfie]
-- ===============================================
IF OBJECT_ID(N'dbo.Tabletasfie', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Tabletasfie] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Tabletasfie]

@ShomareFactor bigint
as 

begin

	select ID, fldCodeTafzili, fldShomareFactor, fldMablagheFactor, fldMablagheDaryafti, fldMablagheMandeFactor, fldMablagheMande, fldSharh, fldDateSarResid, 
                         fldBastan, fldTakhfif, fldSanad
				 from tbltasfie where fldShomareFactor=@ShomareFactor
	
end
GO

-- ===============================================
-- SP: [dbo].[TafzilieDaramad]
-- ===============================================
IF OBJECT_ID(N'dbo.TafzilieDaramad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TafzilieDaramad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[TafziliShow]
-- ===============================================
IF OBJECT_ID(N'dbo.TafziliShow', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TafziliShow] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[TafziliShow]


as 

begin

	update tblTafzili set fldCodeGroup=100 where fldCodeGroup is NULL

	SELECT         tblTafzili.fldCodeTafzili,tblTafzili.fldSharheTafzili, tblTafzili.fldAddress,tblGroupAshkhas.fldGroupName,tblTafzili.fldCodeNoe, tblTafzili.fldCodeGroup 
                         ,tblTafzili.fldNoeHesab
			FROM            tblTafzili INNER JOIN
                         tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
	
end
GO

-- ===============================================
-- SP: [dbo].[tarazname8sotooni]
-- ===============================================
IF OBJECT_ID(N'dbo.tarazname8sotooni', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[tarazname8sotooni] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[tarazname8sotooni]
	@DateFrom bigint,
	@dateuntil bigint
as 
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin

	create table #tblTemp(
		fldNameHesab nvarchar(250) COLLATE Persian_100_CI_AS,
		fldcodehesab nvarchar(10) COLLATE Persian_100_CI_AS,
		fldBedEbteda bigint,
		fldBesEbteda bigint,
		fldBedDore bigint,
		fldBesDore bigint,
		fldBedTaEnteha bigint,
		fldBesTaEnteha bigint,
		fldBedSum bigint,
		fldBesSum bigint
	)
	declare @fldShomareEftetahie bigint,@TooleKol  bigint
	
	delete #tblTemp
	set @TooleKol=(select fldKol from tblPaye)

	insert into #tblTemp	(fldcodehesab,fldNameHesab  )
		select fldcodehesab,fldSharheHesab  from tblKolMoin where len(fldCodeHesab)=@TooleKol
	
	set @fldShomareEftetahie=(select fldShomareEftetahie from tblControlPanel)


	update #tblTemp set fldBedEbteda=tbl1.sumBed,fldBesEbteda=tbl1.sumBes from 
	(SELECT      tblSodooreSanad.fldCodeKol,  sum(tblSodooreSanad.fldBedehkar) as sumBed, sum(tblSodooreSanad.fldBestankar) as sumBes
			FROM            tblSodooreSanad INNER JOIN
                         tblKolMoin ON tblSodooreSanad.fldCodeKol = tblKolMoin.fldCodeHesab where (fldType='checkebteda' or fldtype='checkebtedaPardakhti' or fldType='EbtedaAshkhas' or fldtype='mandebank' or fldType='mojoodieebteda' or fldSanad=@fldShomareEftetahie) and fldDate between @DateFrom and @dateuntil
						 group by fldCodeKol) as tbl1
		where #tblTemp.fldcodehesab=tbl1.fldCodeKol
	
	update #tblTemp set fldBedEbteda=0 where fldBedEbteda is NULL
	update #tblTemp set fldBesEbteda=0 where fldBesEbteda is NULL

		update #tblTemp set fldBedDore=tbl1.sumBed,fldBesDore=tbl1.sumBes from 
	(SELECT      tblSodooreSanad.fldCodeKol,  sum(tblSodooreSanad.fldBedehkar) as sumBed, sum(tblSodooreSanad.fldBestankar) as sumBes
			FROM            tblSodooreSanad INNER JOIN
                         tblKolMoin ON tblSodooreSanad.fldCodeKol = tblKolMoin.fldCodeHesab where not (fldType='checkebteda' or fldtype='checkebtedaPardakhti' or fldType='EbtedaAshkhas' or fldtype='mandebank' or fldType='mojoodieebteda' or fldSanad=@fldShomareEftetahie) and fldDate between @DateFrom and @dateuntil
						 group by fldCodeKol) as tbl1
		where #tblTemp.fldcodehesab=tbl1.fldCodeKol


	update #tblTemp set fldBedDore=0 where fldBedDore is NULL
	update #tblTemp set fldBesDore=0 where fldBesDore is NULL

	update #tblTemp set fldBedTaEnteha=fldBedEbteda+fldBedDore,fldBesTaEnteha=fldBesEbteda+fldBesDore

	update #tbltemp set fldBedSum=(fldBedTaEnteha-fldBesTaEnteha) where fldBedTaEnteha>fldBesTaEnteha
	update #tbltemp set fldBesSum=(fldBesTaEnteha-fldBedTaEnteha) where fldBedTaEnteha<=fldBesTaEnteha

	update #tblTemp set fldBedSum=0 where fldBedSum is NULL
	update #tblTemp set fldBesSum=0 where fldBesSum is NULL

	--select * from #tblTemp
	
	--SELECT        tblSodooreSanad.fldCodeKol, tblSodooreSanad.fldBedehkar, tblSodooreSanad.fldBestankar, tblSodooreSanad.fldDate, tblSodooreSanad.fldType
	--		FROM            tblSodooreSanad INNER JOIN
 --                        tblKolMoin ON tblSodooreSanad.fldCodeKol = tblKolMoin.fldCodeHesab where fldType='checkebteda' or fldtype='checkebtedaPardakhti' or fldType='EbtedaAshkhas' or fldtype='mandebank' or fldType='mojoodieebteda' or fldSanad=@fldShomareEftetahie

	
	

	--SELECT      tblSodooreSanad.fldCodeKol,  sum(tblSodooreSanad.fldBedehkar) as sumBed, sum(tblSodooreSanad.fldBestankar) as sumBes
	--		FROM            tblSodooreSanad INNER JOIN
 --                        tblKolMoin ON tblSodooreSanad.fldCodeKol = tblKolMoin.fldCodeHesab where (fldType='checkebteda' or fldtype='checkebtedaPardakhti' or fldType='EbtedaAshkhas' or fldtype='mandebank' or fldType='mojoodieebteda' ) 
	--					 group by fldCodeKol
	delete #tblTemp Where fldBedEbteda=0 and fldBesEbteda=0 and fldBedDore=0 and fldBesDore=0 
	select fldcodehesab,fldNameHesab,fldBedEbteda,fldBesEbteda,fldBedDore,fldBesDore,fldBedTaEnteha,fldBesTaEnteha,fldBedSum,fldBesSum from #tblTemp
end
GO

-- ===============================================
-- SP: [dbo].[TekrariAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.TekrariAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TekrariAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[TekrariBankeMoshtari]
-- ===============================================
IF OBJECT_ID(N'dbo.TekrariBankeMoshtari', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TekrariBankeMoshtari] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[TekrariKolMoin]
-- ===============================================
IF OBJECT_ID(N'dbo.TekrariKolMoin', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TekrariKolMoin] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[TekrariMablaghPorsantVisitor]
-- ===============================================
IF OBJECT_ID(N'dbo.TekrariMablaghPorsantVisitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TekrariMablaghPorsantVisitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[TekrariMablaghPorsantVisitor]

@MablaghPorsant bigint,
@fldCodeVisitor int,
@fldRadif int,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountPorsant int
	if @IDType=0  --براي مقايسه براي حالت اضافه کردن رکورد
		begin
		 set @RowCountPorsant=(Select Count(fldMablagh) from tblPorsantVisitor  Where fldMablagh=@MablaghPorsant and fldCodeVisitor=@fldCodeVisitor and fldRadif<>@fldRadif)
		 set @flagOUt=@RowCountPorsant
		end
	else
		begin --براي مقايسه با غيرخودش در حالت ويرايش
		   set	@RowCountPorsant=(Select  Count(fldMablagh) from tblPorsantVisitor  Where fldMablagh=@MablaghPorsant and fldCodeVisitor=@fldCodeVisitor and fldRadif<>@fldRadif)
		   set @flagOUt=@RowCountPorsant
		end
end
GO

-- ===============================================
-- SP: [dbo].[TekrariMablaghTakhfif]
-- ===============================================
IF OBJECT_ID(N'dbo.TekrariMablaghTakhfif', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TekrariMablaghTakhfif] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[TekrariMablaghTakhfif]

@MablaghTakhfif bigint,
@ID int,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountTakhfif int
	if @IDType=0  --براي مقايسه براي حالت اضافه کردن رکورد
		begin
		 set @RowCountTakhfif=(Select Count(fldMablagh) from tblTarheTakhfif  Where fldMablagh=@MablaghTakhfif)
		 set @flagOUt=@RowCountTakhfif
		end
	else
		begin --براي مقايسه با غيرخودش در حالت ويرايش
		   set	@RowCountTakhfif=(Select  Count(fldMablagh) from tblTarheTakhfif  Where fldMablagh=@MablaghTakhfif and countRow<>@ID)
		   set @flagOUt=@RowCountTakhfif
		end
end
GO

-- ===============================================
-- SP: [dbo].[TekrariMablaghTakhfifeRadifi]
-- ===============================================
IF OBJECT_ID(N'dbo.TekrariMablaghTakhfifeRadifi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TekrariMablaghTakhfifeRadifi] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[TekrariMablaghTakhfifeRadifi]

@MablaghTakhfif bigint,
@ID int,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountTakhfif int
	if @IDType=0  --براي مقايسه براي حالت اضافه کردن رکورد
		begin
		 set @RowCountTakhfif=(Select Count(fldMablagh) from tblTarheTakhfifeRadifi  Where fldMablagh=@MablaghTakhfif)
		 set @flagOUt=@RowCountTakhfif
		end
	else
		begin --براي مقايسه با غيرخودش در حالت ويرايش
		   set	@RowCountTakhfif=(Select  Count(fldMablagh) from tblTarheTakhfifeRadifi  Where fldMablagh=@MablaghTakhfif and countRow<>@ID)
		   set @flagOUt=@RowCountTakhfif
		end
end
GO

-- ===============================================
-- SP: [dbo].[TekrariVahed]
-- ===============================================
IF OBJECT_ID(N'dbo.TekrariVahed', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TekrariVahed] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[TestCursor]
-- ===============================================
IF OBJECT_ID(N'dbo.TestCursor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TestCursor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[testehsan]
-- ===============================================
IF OBJECT_ID(N'dbo.testehsan', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[testehsan] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[testehsan]
	@dtCheckDaryafti tblCheckDaryafti readonly,
	@s bigint output
	as

BEGIN
    
	set @s=(SELECT count(*) from @dtCheckDaryafti);
END
GO

-- ===============================================
-- SP: [dbo].[TestInsert]
-- ===============================================
IF OBJECT_ID(N'dbo.TestInsert', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TestInsert] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[TESTReport_ListAshkhas_groupby_NameGroup_order_SharhTafsili]
-- ===============================================
IF OBJECT_ID(N'dbo.TESTReport_ListAshkhas_groupby_NameGroup_order_SharhTafsili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TESTReport_ListAshkhas_groupby_NameGroup_order_SharhTafsili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[TestTransaction]
-- ===============================================
IF OBJECT_ID(N'dbo.TestTransaction', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TestTransaction] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[TomanBerial]
-- ===============================================
IF OBJECT_ID(N'dbo.TomanBerial', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[TomanBerial] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[TomanBerial]
@tedadsefr int,
@strResult nvarchar(10) output
as 

begin
	begin transaction AddRecord
		begin try
			UPDATE tblCheckePardakhti 
SET fldMablagh = fldMablagh * POWER(10, @tedadsefr);

UPDATE tblDaftarcheAghsat 
SET fldMablaghGhest = fldMablaghGhest * POWER(10, @tedadsefr);

UPDATE tbleshantionmablagy 
SET fldprice = fldprice * POWER(10, @tedadsefr);

UPDATE tblFee 
SET fldFee = fldFee * POWER(10, @tedadsefr);

UPDATE tblKala 
SET fldFeeBadAzTakhfif = fldFeeBadAzTakhfif * POWER(10, @tedadsefr),
    fldFeeForoosh = fldFeeForoosh * POWER(10, @tedadsefr),
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr);

UPDATE tblMahdoodeMablagheTakhfif 
SET fldMablaghAz = fldMablaghAz * POWER(10, @tedadsefr),
    fldMablaghTa = fldMablaghTa * POWER(10, @tedadsefr);

UPDATE tblMultiFeeDynamic 
SET fldFee = fldFee * POWER(10, @tedadsefr);

UPDATE tblRizeBargashtAzForoosh 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr), 
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr);

UPDATE tblRizeBargashtAzKharid 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr), 
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr);

UPDATE tblRizeFormooleTolid 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr), 
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldHazineTabdil = fldHazineTabdil * POWER(10, @tedadsefr), 
    fldMablagheTakhfif = fldMablagheTakhfif * POWER(10, @tedadsefr);

UPDATE tblRizeForoosh 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr),  
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr);

UPDATE tblRizeKharid  
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr),  
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr), 
    fldHamloNaghl = fldHamloNaghl * POWER(10, @tedadsefr);

UPDATE tblRizePishForoosh 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr),  
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr);

UPDATE tblRizePishPishForoosh 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr),  
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldMablaghTakhfif = fldMablaghTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldArzeshAfzode = fldArzeshAfzode * POWER(10, @tedadsefr), 
    fldFeeKolBadAzTakhfif = fldFeeKolBadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr);

UPDATE tblRizeTasfie 
SET fldMablagh = fldMablagh * POWER(10, @tedadsefr), 
    fldTakhfif = fldTakhfif * POWER(10, @tedadsefr);

UPDATE tblRizeTasfieVam 
SET fldMablagh = fldMablagh * POWER(10, @tedadsefr);

UPDATE tblRizeTolid 
SET fldFeeJoz = fldFeeJoz * POWER(10, @tedadsefr),
    fldFeeYekCarton = fldFeeYekCarton * POWER(10, @tedadsefr), 
    fldFeeKol = fldFeeKol * POWER(10, @tedadsefr), 
    fldFeeVahed1BadAzTakhfif = fldFeeVahed1BadAzTakhfif * POWER(10, @tedadsefr), 
    fldFeeVahed2BadAzTakhfif = fldFeeVahed2BadAzTakhfif * POWER(10, @tedadsefr), 
    fldMablaghKhales = fldMablaghKhales * POWER(10, @tedadsefr), 
    fldHazineTabdil = fldHazineTabdil * POWER(10, @tedadsefr), 
    fldMablagheTakhfif = fldMablagheTakhfif * POWER(10, @tedadsefr), 
    fldGhymatMasrafkonande = fldGhymatMasrafkonande * POWER(10, @tedadsefr);



update tblSodooreSanad
		set fldBedehkar=fldBedehkar *  POWER(10, @tedadsefr),
		fldBestankar=fldBestankar *  POWER(10, @tedadsefr)

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

-- ===============================================
-- SP: [dbo].[ToolePaye]
-- ===============================================
IF OBJECT_ID(N'dbo.ToolePaye', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ToolePaye] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[typeSanad]
-- ===============================================
IF OBJECT_ID(N'dbo.typeSanad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[typeSanad] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[typeSanad] 
	-- Add the parameters for the stored procedure here
	@Sanad bigint,
	@strType nvarchar(20) output,
	@Shomare bigint output
AS
BEGIN
	declare @bigCount bigint

	set @strType=''
	--فروش
   	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 tblDaryaft where fldShomareSanad=@Sanad And fldType='daramad')
	if @bigCount>0
		begin
			set @strType='daramad'
			set @shomare = (select  fldShomareDaryaft  from tblDaryaft where fldShomareSanad=@Sanad And fldType='daramad')
		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

	
	--انتقال وجه
   	set @bigCount = (select  count(fldShomareSanad) as cnt from tblPardakht where fldShomareSanad=@Sanad And fldType='enteghalevajh')
	if @bigCount>0
		begin
			set @strType='enteghalevajh'
			set @shomare = (select  fldShomarePardakht  from tblPardakht where fldShomareSanad=@Sanad And fldType='enteghalevajh')
		end

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


	--وصول چک
   	set @bigCount = (select  count(fldShomareSanad) as cnt from tblVosool where fldShomareSanad=@Sanad )
	if @bigCount>0
		begin
			set @strType='vosool'
			set @shomare = (select  fldShomareVosool  from tblVosool where fldShomareSanad=@Sanad )
		end

		--پاس چک
   	set @bigCount = (select  count(fldShomareSanad) as cnt from tblPas where fldShomareSanad=@Sanad )
	if @bigCount>0
		begin
			set @strType='pasecheck'
			set @shomare = (select  fldShomarePas  from tblPas where fldShomareSanad=@Sanad )
		end
	--
   	set @bigCount = (select  count(fldSanad) as cnt from tblSodooreSanad where fldSanad=@Sanad And fldType='EbtedaAshkhas')
	if @bigCount>0
		begin
			set @strType='EbtedaAshkhas'
		end

	if @strType=''
		set @strType='sanaddasti'
END
GO

-- ===============================================
-- SP: [dbo].[UpadteChap]
-- ===============================================
IF OBJECT_ID(N'dbo.UpadteChap', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpadteChap] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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),
	@fldPasafhePishFactor 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
	update tblChap 
		set fldNameMoassese= @fldNameMoassese ,
			fldTozihateBala=@fldTozihateBala ,
			fldAdress=@fldAdress ,
			fldPasafhe=@fldPasafhe ,
			fldCodeEghtesadi=@fldCodeEghtesadi ,
			fldShomareSabt=@fldShomareSabt ,
			fldCodePosti=@fldCodePosti ,
			fldTell=@fldTell ,
			fldPasafhePishFactor=@fldPasafhePishFactor
	
	update tblControlPanel
		set fldNameSherkat=@fldNameMoassese
END
GO

-- ===============================================
-- SP: [dbo].[Update_SuperVizor]
-- ===============================================
IF OBJECT_ID(N'dbo.Update_SuperVizor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Update_SuperVizor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[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

-- ===============================================
-- SP: [dbo].[Update_Tbl_DaftarcheTell_Has_CodeTafisili]
-- ===============================================
IF OBJECT_ID(N'dbo.Update_Tbl_DaftarcheTell_Has_CodeTafisili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Update_Tbl_DaftarcheTell_Has_CodeTafisili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[Update_Tbl_DaftarcheTell_NotHas_CodeTafisili]
-- ===============================================
IF OBJECT_ID(N'dbo.Update_Tbl_DaftarcheTell_NotHas_CodeTafisili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Update_Tbl_DaftarcheTell_NotHas_CodeTafisili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[Update_Tbl_Tafsili]
-- ===============================================
IF OBJECT_ID(N'dbo.Update_Tbl_Tafsili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Update_Tbl_Tafsili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

update tblDaftarcheTell set fldName=@fldSharheTafzili where fldCodeTafzili=@fldCodeTafzili

set @flagUpdateOK=1
END
GO

-- ===============================================
-- SP: [dbo].[Update_Tbl_Tafsili_2]
-- ===============================================
IF OBJECT_ID(N'dbo.Update_Tbl_Tafsili_2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Update_Tbl_Tafsili_2] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[Update_Tbl_Tafsili_2]
@fldNoeHesab	nvarchar(15),	
@fldSharheTafzili	nvarchar(200),
@fldCodeTafzili	nvarchar(10),	
@fldCodeNoe	nvarchar(5),	--set "1"
@fldNoe	nvarchar(10),	
@fldCodeGroup	bigint,	 
@fldCodeGroup2  bigint,
@fldOstan	nvarchar(50),	
@fldCity	nvarchar(50),	
@fldAddress	nvarchar(200),	
@fldShomareHesab	nvarchar(20),	
@fldCodeMeli	nvarchar(20),	
@fldCodeEghtesadi	nvarchar(20),	
@fldDescription nvarchar(250),
@fldCodePosti	nvarchar(20),	
@fldShomareSabt	nvarchar(20),	
@fldSaghfeEtebar	decimal,
@fldBlackList	nvarchar(5),	
@fldSharhBlackList	nvarchar(100),	
@fldDate1	bigint,	
@fldDate2	bigint,	
@fldVisitor	bigint,	
@fldPic	nvarchar(300),
@fldDarsadTakhfif decimal(18,2),
@fldHaghighi int,
@fldname nvarchar(30),
@fldShobe nvarchar(15),
@fldCodeNaghsh nvarchar(20),
@NoeSooratMoadian int,
@flagUpdateOK int output

as
begin
set @fldVisitor=isnull(@fldVisitor,0)
update  tblTafzili
set fldNoeHesab='',
    fldSharheTafzili=@fldSharheTafzili,
	fldCodeNoe=@fldCodeNoe,
	fldNoe=@fldNoe,
	fldCodeGroup=@fldCodeGroup,
	fldCodeGroup2=@fldCodeGroup2,
	fldOstan=@fldOstan,
	fldCity=@fldCity,
	fldAddress=@fldAddress,
	fldShomareHesab=@fldShomareHesab,
	fldCodeMeli=@fldCodeMeli,
	fldCodeEghtesadi=@fldCodeEghtesadi,
	fldDescription =@fldDescription ,
	fldCodePosti=@fldCodePosti,
	fldShomareSabt=@fldShomareSabt,
	fldSaghfeEtebar=@fldSaghfeEtebar,
	fldBlackList=@fldBlackList,
	fldSharhBlackList=@fldSharhBlackList,
	fldDate1=@fldDate1,
	fldDate2=@fldDate2,
	fldVisitor=@fldVisitor,
	fldPic=@fldPic,
	fldDarsadTakhfif=@fldDarsadTakhfif,
	fldName=@fldName,
	fldshobe=@fldshobe,
	fldCodeNaghsh=@fldCodeNaghsh,
	fldHaghighi=@fldHaghighi,
	fldNoeSooratMoadian=@NoeSooratMoadian
where fldCodeTafzili=@fldCodeTafzili

update tblDaftarcheTell set fldName=@fldSharheTafzili where fldCodeTafzili=@fldCodeTafzili

set @flagUpdateOK=1
END
GO

-- ===============================================
-- SP: [dbo].[Update_Vizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.Update_Vizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Update_Vizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[Update_Vizitor] 
	@ID bigint,
	@fldPoorsant decimal(18,2),
	@fldSharheTafzili nvarchar(200),
	@fldNoeMohasebePoorsant int,
	@CodeSuperVisor nvarchar(10),
	@SaghfeEtebar decimal
AS
BEGIN
	update tblTafzili set fldSharheTafzili=@fldSharheTafzili,fldPoorsant=@fldPoorsant,
			fldNoeMohasebePoorsant=@fldNoeMohasebePoorsant,fldCodeSuperVisor=@CodeSuperVisor,fldSaghfeEtebar=@SaghfeEtebar
		where ID=@ID
		
	
END
GO

-- ===============================================
-- SP: [dbo].[Update_Vizitor2]
-- ===============================================
IF OBJECT_ID(N'dbo.Update_Vizitor2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[Update_Vizitor2] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[Update_Vizitor2] 
	@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

-- ===============================================
-- SP: [dbo].[UpdateBank]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateBank', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateBank] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[UpdateBank]

@ID int,
@NameHesab nvarchar(70),
@CodeType nvarchar(5),
@SharheNoeTafzili nvarchar(20),
@ShomareHesab nvarchar(50),
@Mande decimal(18,2),
@flddate bigint,
@flagOut int output
as

begin
	declare @cntSanad int,@CodeHesab nvarchar(20),@year int,@month int,@day int,@yearFull int
	Update tblKolMoin Set fldSharheHesab =@NameHesab,fldCodeNoeHesab=@CodeType,fldNoeHesab=@SharheNoeTafzili,fldInfo=@ShomareHesab Where ID=@id

	set @CodeHesab=(Select  fldCodeHesab from tblKolMoin Where id=@id)
	--select * from tblSodooreSanad where fldsanad =16

	set @cntSanad= (select count(id) as cnt from  tblSodooreSanad where fldType='mandebank' and fldMoinKamel=@CodeHesab)

	set @yearFull=substring(convert(nvarchar(20),@flddate),0,5)
	set @year=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)

	if @cntSanad>0 
		begin
			declare @Sanad bigint
			set @Sanad=(Select top(1)fldSanad from tblSodooreSanad  where fldType='mandebank' and fldMoinKamel=@CodeHesab  )


			if @Mande=0 
				begin
					delete tblSodooreSanad where fldSanad=@Sanad
					set @flagOut=1
					return
				end
			else
				delete tblSodooreSanad where fldSanad=@Sanad
		end
	
		
			declare @TooleKol bigint,@Toolemoin bigint,@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@fldShomareSanad bigint,@fldCodeKolSarmaye int
			execute  ToolePaye 'kol',@TooleKol output
			execute  ToolePaye 'moin',@Toolemoin output
			--execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
			set @CodeKolkham =substring(convert(varchar,@CodeHesab), 1, @TooleKol)
			set @CodeMoinKham =substring(convert(varchar,@CodeHesab),@TooleKol+1,@Toolemoin)

			

			execute CodeKolHesab 'sarmaye',@fldCodeKolSarmaye output

			execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeHesab,'','1',@Mande,0,1,@fldDate,'مانده ابتدای دوره بانک',@day,@month,@year,'mandebank','',@fldShomareSanad output 
			execute InsertSanadLast @fldCodeKolSarmaye,'',@fldCodeKolSarmaye,'','',0,@Mande,2,@fldDate,'مانده ابتدای دوره بانک',@day,@month,@year,'mandebank','',@fldShomareSanad
		

	set @flagOut=1
end
GO

-- ===============================================
-- SP: [dbo].[UpdateBankeMa]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateBankeMa', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateBankeMa] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[UpdateBankeMa]
@CodeBank nvarchar(50),
@NameBank nvarchar(50),
@idSabt int output
as
begin
		declare @id int

	set	@id=(select ID from tblKolMoin where fldCodeHesab=@CodeBank)

		
		execute UpdateTblKolMoin @id,@NameBank,'تفصيلي ندارد','4',@idSabt
end
GO

-- ===============================================
-- SP: [dbo].[UpdateDaftarCheTelPersonel]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateDaftarCheTelPersonel', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateDaftarCheTelPersonel] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[UpdateGroupAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateGroupAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateGroupAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[UpdateGroupAshkhas]
@fldGroupAshkhasId bigint,
@fldGroupAshkhasName nvarchar(50),
@flagduplicate  int output
AS

Begin
if not Exists(select fldGroupName  from tblGroupAshkhas where fldGroupName=@fldGroupAshkhasName and  fldGroupId<> @fldGroupAshkhasId)
	 begin
		update tblGroupAshkhas
		set fldGroupName=@fldGroupAshkhasName
		where fldGroupId=@fldGroupAshkhasId

		set @flagduplicate=0 
	 end
 else
	 begin
		set @flagduplicate=1
	 end
end
GO

-- ===============================================
-- SP: [dbo].[UpdateGroupKala]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateGroupKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateGroupKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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 and len(fldGroupId)= len(@fldGroupKalaId) and fldGroupId like   substring(convert(nvarchar,@fldGroupKalaId),1,len(@fldGroupKalaId)-3) + '%')
 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

-- ===============================================
-- SP: [dbo].[UpdateSandoogh]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateSandoogh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateSandoogh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[UpdateSandoogh]
@CodeSandoogh nvarchar(50),
@NameSandoogh nvarchar(50),
@idSabt int output
as
begin
		declare @id int

	set	@id=(select ID from tblKolMoin where fldCodeHesab=@CodeSandoogh)

		
		execute UpdateTblKolMoin @id,@NameSandoogh,'تفصيلي ندارد','4',@idSabt
end
GO

-- ===============================================
-- SP: [dbo].[UpdateSandooghNew]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateSandooghNew', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateSandooghNew] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[UpdateSandooghNew]

@ID int,
@NameHesab nvarchar(70),
@CodeType nvarchar(5),
@SharheNoeTafzili nvarchar(20),
@ShomareHesab nvarchar(50),
@Mande decimal(18,2),
@flddate bigint,
@flagOut int output
as

begin
	declare @cntSanad int,@CodeHesab nvarchar(20),@year int,@month int,@day int,@yearFull int
	Update tblKolMoin Set fldSharheHesab =@NameHesab,fldCodeNoeHesab=@CodeType,fldNoeHesab=@SharheNoeTafzili,fldInfo=@ShomareHesab Where ID=@id

	set @CodeHesab=(Select  fldCodeHesab from tblKolMoin Where id=@id)
	--select * from tblSodooreSanad where fldsanad =16

	set @cntSanad= (select count(id) as cnt from  tblSodooreSanad where fldType='mandesandoogh' and fldMoinKamel=@CodeHesab)

	set @yearFull=substring(convert(nvarchar(20),@flddate),0,5)
	set @year=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)

	if @cntSanad>0 
		begin
			declare @Sanad bigint
			set @Sanad=(Select top(1)fldSanad from tblSodooreSanad  where fldType='mandesandoogh' and fldMoinKamel=@CodeHesab  )


			if @Mande=0 
				begin
					delete tblSodooreSanad where fldSanad=@Sanad
					set @flagOut=1
					return
				end
			else
				delete tblSodooreSanad where fldSanad=@Sanad
		end
	
		
			declare @TooleKol bigint,@Toolemoin bigint,@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10),@fldShomareSanad bigint,@fldCodeKolSarmaye int
			execute  ToolePaye 'kol',@TooleKol output
			execute  ToolePaye 'moin',@Toolemoin output
			--execute codemoinhesab 'hesabhayedaryaftani' ,@CodeMoinHesabhayeDaryaftani output
			set @CodeKolkham =substring(convert(varchar,@CodeHesab), 1, @TooleKol)
			set @CodeMoinKham =substring(convert(varchar,@CodeHesab),@TooleKol+1,@Toolemoin)

			

			execute CodeKolHesab 'sarmaye',@fldCodeKolSarmaye output

			execute InsertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeHesab,'','1',@Mande,0,1,@fldDate,'مانده ابتدای دوره صندوق',@day,@month,@year,'mandesandoogh','',@fldShomareSanad output 
			execute InsertSanadLast @fldCodeKolSarmaye,'',@fldCodeKolSarmaye,'','',0,@Mande,2,@fldDate,'مانده ابتدای دوره صندوق',@day,@month,@year,'mandesandoogh','',@fldShomareSanad
		

	set @flagOut=1
end
GO

-- ===============================================
-- SP: [dbo].[UpdateTblAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateTblAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateTblAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[UpdateTblAnbar]

@ID int,
@NameAnbar nvarchar(70),
@CodePosti nvarchar(25),
@flagOut int output
as

begin
	Update tblAnbar Set fldNameAnbar=@NameAnbar,fldCodeposti=@CodePosti Where ID=@id
	set @flagOut=1
end
GO

-- ===============================================
-- SP: [dbo].[UpdateTblBankeMoshtari]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateTblBankeMoshtari', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateTblBankeMoshtari] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[UpdateTblKala]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateTblKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateTblKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[UpdateTblKolMoin]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateTblKolMoin', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateTblKolMoin] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[UpdateTblPorsantVisitor]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateTblPorsantVisitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateTblPorsantVisitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[UpdateTblPorsantVisitor]

@fldRadif int,
@fldMablagh decimal,
@fldDarsad decimal(18,2),
@flagOut int output
as

begin
	Update tblPorsantVisitor Set fldMablagh =@fldMablagh,fldDarsad=@fldDarsad Where fldRadif=@fldRadif
	set @flagOut=1
end
GO

-- ===============================================
-- SP: [dbo].[UpdateTblTafziliIdCaller]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateTblTafziliIdCaller', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateTblTafziliIdCaller] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter 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

-- ===============================================
-- SP: [dbo].[UpdateTblTarheTakhfif]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateTblTarheTakhfif', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateTblTarheTakhfif] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[UpdateTblTarheTakhfif]

@ID int,
@fldMablagh decimal,
@fldDarsad decimal(18,2),
@flagOut int output
as

begin
	Update tblTarheTakhfif Set fldMablagh =@fldMablagh,fldDarsad=@fldDarsad Where countRow=@id
	set @flagOut=1
end
GO

-- ===============================================
-- SP: [dbo].[UpdateTblTarheTakhfifeRadifi]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateTblTarheTakhfifeRadifi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateTblTarheTakhfifeRadifi] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[UpdateTblTarheTakhfifeRadifi]

@ID int,
@fldMablagh decimal,
@fldDarsad decimal(18,2),
@flagOut int output
as

begin
	Update tblTarheTakhfifeRadifi Set fldMablagh =@fldMablagh,fldDarsad=@fldDarsad Where countRow=@id
	set @flagOut=1
end
GO

-- ===============================================
-- SP: [dbo].[UpdateTblVahed]
-- ===============================================
IF OBJECT_ID(N'dbo.UpdateTblVahed', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[UpdateTblVahed] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter 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

-- ===============================================
-- SP: [dbo].[usp_InsertProductionLocation]
-- ===============================================
IF OBJECT_ID(N'dbo.usp_InsertProductionLocation', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[usp_InsertProductionLocation] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[usp_InsertProductionLocation]  
    @TVP LocationTableType READONLY  
    AS   
    SET NOCOUNT ON  
    INSERT INTO tblTest5 
           (name1,  
            id) 
        SELECT *
        FROM  @TVP;
GO

-- ===============================================
-- SP: [dbo].[z100HavaleGoroohi]
-- ===============================================
IF OBJECT_ID(N'dbo.z100HavaleGoroohi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z100HavaleGoroohi] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z100HavaleGoroohi] 
	-- Add the parameters for the stored procedure here
	@strWhere nvarchar(4000),
	@intorder int,
	@lngSumTedadejoz float output,
	@lngSumTedadeKol bigint 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;

    -- Insert statements for procedure here

	create table #tmpHavale
		(
			fldCodeKala bigint,
			fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
			fldSumJoz float,
			fldTedadDarKarton decimal(18,0),
			fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
			fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS ,
			fldTedadKartonadadSahih bigint,
			fldNameVahed2 NVarchar(100) COLLATE Persian_100_CI_AS,
			fldCodeVahed1 bigint,
			fldCodeVahed2 bigint,
			fldHajm decimal(18,2),
			fldGheimatMasrafkonande decimal(18,0)
		)

  execute('insert into #tmpHavale 
		(fldCodeKala,fldNameKala,fldTedadDarKarton,fldSumJoz, fldCodeVahed1,fldCodeVahed2)
		SELECT        tblRizeForoosh.fldCodeKala, tblKala.fldNameKala,tblKala.fldTedadJoz,Convert(float, SUM(tblRizeForoosh.fldTedadJoz)) AS SumM,tblKala.fldCodeVahed1,tblKala.fldCodeVahed2
		FROM            tblRizeForoosh INNER JOIN
								 tblKala ON tblRizeForoosh.fldCodeKala = tblKala.fldCodeKala '
						 + @strWhere + 
		
		 ' GROUP BY tblRizeForoosh.fldCodeKala,  tblKala.fldNameKala,tblKala.fldTedadJoz ,tblKala.fldCodeVahed1,tblKala.fldCodeVahed2 ')





--تعداد کارتن و تعداد جز در آن
update #tmpHavale set fldNameVahed2='' where fldTedadDarKarton=0


update #tmpHavale set #tmpHavale.fldNameVahed=tbl2.fldNameVahed,#tmpHavale.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 #tmpHavale.fldCodeKala=tbl2.fldCodeKala


update #tmpHavale Set fldTedadDarKartonShow=Convert(varchar,floor(Convert(dec,fldSumJoz) /Convert(dec, fldTedadDarKarton))) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,fldSumJoz), Convert(dec, fldTedadDarKarton)) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #tmpHavale set fldNameVahed='' where fldCodeVahed1=1
update #tmpHavale set fldNameVahed2='' where fldCodeVahed2=1
--update #tmpHavale Set fldTedadVoroodKartonShow=Convert(varchar,floor(SumVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(SumVorood, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--	where fldTedadDarKarton>0

--update #tmpHavale Set fldTedadKhoroojKartonShow=Convert(varchar,floor(SumKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Sumkhorooj, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--	where fldTedadDarKarton>0
update #tmpHavale set fldTedadKartonadadSahih=(fldSumJoz/fldTedadDarKarton)   Where fldTedadDarKarton>0
update #tmpHavale set fldTedadKartonadadSahih=0 Where isnumeric(fldTedadKartonadadSahih)=0

update #tmpHavale set fldHajm=fldSumJoz*tblKala.fldhajm from tblKala Where #tmpHavale.fldCodeKala=tblKala.fldCodeKala
update #tmpHavale set fldHajm=0  Where fldHajm is NULL

set @lngSumTedadejoz=(Select Sum(fldSumJoz) from #tmpHavale)
set @lngSumTedadeKol=(Select Sum(fldTedadKartonadadSahih) from #tmpHavale)

update #tmpHavale set fldGheimatMasrafkonande=tblkala.fldGhymatMasrafkonande from tblkala where #tmpHavale.fldCodeKala=tblKala.fldCodeKala
update #tmpHavale set fldGheimatMasrafkonande=0 where fldGheimatMasrafkonande is null 


	if @intorder=0  --مرتب سازی براساس کد کالا
		Select fldCodeKala,fldNameKala,fldSumJoz, fldNameVahed,fldTedadDarKarton,fldTedadDarKartonShow,fldNameVahed2,fldHajm,fldGheimatMasrafkonande from #tmpHavale order by fldCodeKala


	if @intorder=1  --مرتب سازی براساس نام کالا
		Select fldCodeKala,fldNameKala,fldSumJoz, fldNameVahed,fldTedadDarKarton,fldTedadDarKartonShow,fldNameVahed2,fldHajm,fldGheimatMasrafkonande from #tmpHavale order by fldNameKala


	if @intorder=2  --مرتب سازی براساس تعداد جز
		Select fldCodeKala,fldNameKala,fldSumJoz, fldNameVahed,fldTedadDarKarton,fldTedadDarKartonShow,fldNameVahed2,fldHajm,fldGheimatMasrafkonande from #tmpHavale order by fldSumJoz


	--execute('SELECT        tblRizeForoosh.fldCodeKala, tblKala.fldNameKala, SUM(tblRizeForoosh.fldTedadJoz) AS SumM
	--	FROM            tblRizeForoosh INNER JOIN
	--							 tblKala ON tblRizeForoosh.fldCodeKala = tblKala.fldCodeKala '
	--					 + @strWhere + 
		
	--	' GROUP BY tblRizeForoosh.fldCodeKala,  tblKala.fldNameKala ')

END
GO

-- ===============================================
-- SP: [dbo].[z100HavaleGoroohiPishfactor]
-- ===============================================
IF OBJECT_ID(N'dbo.z100HavaleGoroohiPishfactor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z100HavaleGoroohiPishfactor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z100HavaleGoroohiPishfactor] 
	-- Add the parameters for the stored procedure here
	@strWhere nvarchar(4000),
	@intorder int,
	@lngSumTedadejoz float output,
	@lngSumTedadeKol bigint 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;

    -- Insert statements for procedure here

	create table #tmpHavale
		(
			fldCodeKala bigint,
			fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
			fldSumJoz float,
			fldTedadDarKarton decimal(18,0),
			fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
			fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS ,
			fldTedadKartonadadSahih bigint,
			fldNameVahed2 NVarchar(100) COLLATE Persian_100_CI_AS,
			fldCodeVahed1 bigint,
			fldCodeVahed2 bigint,
			fldHajm decimal(18,2),
			fldGheimatMasrafkonande decimal(18,0)
		)

  execute('insert into #tmpHavale 
		(fldCodeKala,fldNameKala,fldTedadDarKarton,fldSumJoz, fldCodeVahed1,fldCodeVahed2)
		SELECT        tblRizePishPishForoosh.fldCodeKala, tblKala.fldNameKala,tblKala.fldTedadJoz,Convert(float, SUM(tblRizePishPishForoosh.fldTedadJoz)) AS SumM,tblKala.fldCodeVahed1,tblKala.fldCodeVahed2
		FROM            tblRizePishPishForoosh INNER JOIN
								 tblKala ON tblRizePishPishForoosh.fldCodeKala = tblKala.fldCodeKala '
						 + @strWhere + 
		
		 ' GROUP BY tblRizePishPishForoosh.fldCodeKala,  tblKala.fldNameKala,tblKala.fldTedadJoz ,tblKala.fldCodeVahed1,tblKala.fldCodeVahed2 ')





--تعداد کارتن و تعداد جز در آن
update #tmpHavale set fldNameVahed2='' where fldTedadDarKarton=0


update #tmpHavale set #tmpHavale.fldNameVahed=tbl2.fldNameVahed,#tmpHavale.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 #tmpHavale.fldCodeKala=tbl2.fldCodeKala


update #tmpHavale Set fldTedadDarKartonShow=Convert(varchar,floor(Convert(dec,fldSumJoz) /Convert(dec, fldTedadDarKarton))) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,fldSumJoz), Convert(dec, fldTedadDarKarton)) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #tmpHavale set fldNameVahed='' where fldCodeVahed1=1
update #tmpHavale set fldNameVahed2='' where fldCodeVahed2=1
--update #tmpHavale Set fldTedadVoroodKartonShow=Convert(varchar,floor(SumVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(SumVorood, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--	where fldTedadDarKarton>0

--update #tmpHavale Set fldTedadKhoroojKartonShow=Convert(varchar,floor(SumKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Sumkhorooj, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--	where fldTedadDarKarton>0
update #tmpHavale set fldTedadKartonadadSahih=(fldSumJoz/fldTedadDarKarton)   Where fldTedadDarKarton>0
update #tmpHavale set fldTedadKartonadadSahih=0 Where isnumeric(fldTedadKartonadadSahih)=0

update #tmpHavale set fldHajm=fldSumJoz*tblKala.fldhajm from tblKala Where #tmpHavale.fldCodeKala=tblKala.fldCodeKala
update #tmpHavale set fldHajm=0  Where fldHajm is NULL


select * from #tmpHavale
set @lngSumTedadejoz=(Select Sum(fldSumJoz) from #tmpHavale)
set @lngSumTedadeKol=(Select Sum(fldTedadKartonadadSahih) from #tmpHavale)

update #tmpHavale set fldGheimatMasrafkonande=tblkala.fldGhymatMasrafkonande from tblkala where #tmpHavale.fldCodeKala=tblKala.fldCodeKala
update #tmpHavale set fldGheimatMasrafkonande=0 where fldGheimatMasrafkonande is null 


	if @intorder=0  --مرتب سازی براساس کد کالا
		Select fldCodeKala,fldNameKala,fldSumJoz, fldNameVahed,fldTedadDarKarton,fldTedadDarKartonShow,fldNameVahed2,fldHajm,fldGheimatMasrafkonande from #tmpHavale order by fldCodeKala


	if @intorder=1  --مرتب سازی براساس نام کالا
		Select fldCodeKala,fldNameKala,fldSumJoz, fldNameVahed,fldTedadDarKarton,fldTedadDarKartonShow,fldNameVahed2,fldHajm,fldGheimatMasrafkonande from #tmpHavale order by fldNameKala


	if @intorder=2  --مرتب سازی براساس تعداد جز
		Select fldCodeKala,fldNameKala,fldSumJoz, fldNameVahed,fldTedadDarKarton,fldTedadDarKartonShow,fldNameVahed2,fldHajm,fldGheimatMasrafkonande from #tmpHavale order by fldSumJoz


	--execute('SELECT        tblRizePishForoosh.fldCodeKala, tblKala.fldNameKala, SUM(tblRizePishForoosh.fldTedadJoz) AS SumM
	--	FROM            tblRizePishForoosh INNER JOIN
	--							 tblKala ON tblRizePishForoosh.fldCodeKala = tblKala.fldCodeKala '
	--					 + @strWhere + 
		
	--	' GROUP BY tblRizePishForoosh.fldCodeKala,  tblKala.fldNameKala ')

END
GO

-- ===============================================
-- SP: [dbo].[z101ExecueQuery]
-- ===============================================
IF OBJECT_ID(N'dbo.z101ExecueQuery', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z101ExecueQuery] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z101ExecueQuery] 
	@strQuery varchar(5000)=null
	--@ListCodeAshkhas varchar(5000)=null,
	--@ListCodeVisitor varchar(5000)=null,
	--@DataType varchar(40),
	--@DateFrom varchar(8),
	--@DateTo varchar(8),
	--@FlagSort Varchar(5)
	--@strQuery varhar(5000)=null
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	execute (@strQuery)

END
GO

-- ===============================================
-- SP: [dbo].[z102InsertHavaleGoroohi]
-- ===============================================
IF OBJECT_ID(N'dbo.z102InsertHavaleGoroohi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z102InsertHavaleGoroohi] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z102InsertHavaleGoroohi]
	-- Add the parameters for the stored procedure here
	
	@tblShomareFactor dtlisteforoosh readonly,	
	@fldDate bigint,
	@fldCodeRanande bigint,
	@fldCodeMovaze bigint,
	@fldCodeAnbarDar bigint,
	@fldShomareHavale bigint,
	@type nvarchar(10),
	@NoeKhata nvarchar(10) output
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


--اگر شماره حواله صفر اومد یعنی شماره جدید ثبت بشه
--در غیر اینصورت اصلاحه
	declare @maxShomareHavale bigint
		
begin transaction transact
	begin try
		set @maxShomareHavale=(Select Max(fldShomareHavale) as MaxShomare from tblHavaleGoroohi)
		if @maxShomareHavale is null	
			set @maxShomareHavale=0

		set @maxShomareHavale=@maxShomareHavale+1

		if @fldShomareHavale>0 
			begin
				delete from tblHavaleGoroohi where fldShomareHavale=@fldShomareHavale
				set @maxShomareHavale=@fldShomareHavale
			end

		

		INSERT INTO tblHavaleGoroohi
			(fldShomareFactor, fldShomareHavale, fldDate, fldCodeRanande,fldCodeMovaze,fldCodeAnbarDar,fldType)
			select fldShomareFactor,@maxShomareHavale,@fldDate,@fldCodeRanande,@fldCodeMovaze,@fldCodeAnbarDar,@type  from @tblShomarefactor
	

		set @NoeKhata=convert(varchar,@maxShomareHavale)


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


		end catch
		

END
GO

-- ===============================================
-- SP: [dbo].[z103ReportCheckDaryafti]
-- ===============================================
IF OBJECT_ID(N'dbo.z103ReportCheckDaryafti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z103ReportCheckDaryafti] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z103ReportCheckDaryafti]
@Type nvarchar(20),
@ListGroupAshkhas varchar(5000)=null,
@ListCodeAshkhas varchar(5000)=null,
@ListCodeVisitor varchar(5000)=null,
@DateSarResidAz bigint,
@DateSarResidTa bigint,
@DateDaryaftAz bigint,
@DateDaryaftTa bigint,
@JameMablagh bigint output

	
AS
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
BEGIN
	
SET NOCOUNT ON;


create table #TempReportCheck(

ID bigint,
fldShomareCheck nvarchar(30),
fldShomareHesab bigint,
fldCodeSahebeCheck Nvarchar(10) collate Persian_100_CI_AS,
fldSharheTafzili  Nvarchar(200) collate Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldDateSarResid bigint,
fldDateSarResidShow  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeBank int, 
fldNameBank Nvarchar(100) collate Persian_100_CI_AS, 
fldShobe Nvarchar(40) collate Persian_100_CI_AS,
fldMablagh decimal(18,0),
fldDateDaryaft bigint, 
fldDateDaryaftShow Nvarchar(20) collate Persian_100_CI_AS,
fldShomareDaryaft bigint,
fldVaziat  Nvarchar(15) collate Persian_100_CI_AS,
fldShomarePardakht bigint,
fldShomareVosool bigint,
fldDateVosool bigint,
fldDateVosoolShow nvarchar(15) collate Persian_100_CI_AS,
fldVaziatShow nvarchar(200)  collate Persian_100_CI_AS,
fldSanadVosool bigint,
fldCodeHesabeVosool bigint,
fldNameHesabeVosool nvarchar(200)  collate Persian_100_CI_AS,
fldCodeBankVagozari bigint,
fldNameBankVagozari nvarchar(200)  collate Persian_100_CI_AS,
fldDateVagozariBeBank bigint,
fldDateVagozariBeBankShow nvarchar(20)  collate Persian_100_CI_AS,
fldCodeVasete nvarchar(10)  collate Persian_100_CI_AS,
fldNameVasete nvarchar(200) collate Persian_100_CI_AS,
fldNameGroupAshkhas nvarchar(80) collate Persian_100_CI_AS

)

--if @type='all'
	begin

	--براي انتقال چکهای ابتدای دوره
	--##################################################################################################################
	update tblCheckeDaryafti set fldVaziat='vagozari' where ISNUMERIC( fldDateVagozariBeBank )=1 and fldVaziat is null
	update tblCheckeDaryafti set fldVaziat='vosool' where ISNUMERIC( fldDateVosool )=1 and fldVaziat is null
	update tblCheckeDaryafti set fldVaziat='forooshecheck' where ISNUMERIC( fldShomarePardakht )=1 and fldVaziat is null
	update tblCheckeDaryafti set fldVaziat='Bargasht' where ISNUMERIC( fldDateBargasht )=1 and fldVaziat is null
	--##################################################################################################################

	Insert into  #TempReportCheck(ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDateDaryaft,fldDateDaryaftShow,fldShomareDaryaft,fldVaziat,fldShomarePardakht,
			fldShomareVosool,fldDateVosool,fldDateVosoolShow,fldSanadVosool,fldCodeHesabeVosool,fldCodeBankVagozari,fldDateVagozariBeBank,fldDateVagozariBeBankShow,fldCodeVasete
			 )
		SELECT        dbo.tblCheckeDaryafti.ID,dbo.tblCheckeDaryafti.fldShomareCheck,dbo.tblCheckeDaryafti.fldShomareHesab,dbo.tblCheckeDaryafti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldCodeGroup,fldDateSarResid,
								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,fldDateDaryaft, 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,
								 fldShomareVosool,fldDateVosool,
								 SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVosool), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVosool), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVosool), 7, 2) AS fldDateVosoolShow,
								 dbo.tblCheckeDaryafti.fldSanadVosool,dbo.tblCheckeDaryafti.fldCodeHesabeVosool,dbo.tblCheckeDaryafti.fldCodeBankVagozari,fldDateVagozariBeBank,
								 SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVagozariBeBank), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVagozariBeBank), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVagozariBeBank), 7, 2) AS fldDateVagozariBeBankShow,tblCheckeDaryafti.fldVasete
                         
		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									 
					order by tblCheckeDaryafti.fldDateSarResid,tblCheckeDaryafti.fldDateDaryaft
	end
--else if @type='vosoolnashode'
--	SELECT        dbo.tblCheckeDaryafti.ID,dbo.tblCheckeDaryafti.fldShomareCheck,dbo.tblCheckeDaryafti.fldShomareHesab,dbo.tblCheckeDaryafti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldDateSarResid,
--								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')
--					order by tblCheckeDaryafti.fldDateSarResid,tblCheckeDaryafti.fldDateDaryaft

--if @type<>'search' 
--	if @ListGroupAshkhas<>''
--		begin
--		declare @StrDeleteGroupAshkhas varchar(5000)
--		set  @StrDeleteGroupAshkhas='delete from #TempReportCheck 
--			where '+ @ListGroupAshkhas + ''
--			execute(@StrDeleteGroupAshkhas)
--		end


if @ListCodeAshkhas <>''
begin
	declare @StrDeleteAshkhas varchar(5000)
	set  @StrDeleteAshkhas='delete from #TempReportCheck 
		where fldCodeSahebeCheck NOT IN ('+ @ListCodeAshkhas +')'
		execute(@StrDeleteAshkhas)
end


if @ListCodeVisitor<>''
	begin
	if @ListCodeVisitor='-1' --لیست فاکتورهای بدون ویزیتور
		begin
			delete from #TempReportCheck where fldCodeVasete<>''
		end
	else
		begin
			declare @StrDeleteVisitor varchar(5000)
			set  @StrDeleteVisitor='delete from #TempReportCheck 
				where '+ @ListCodeVisitor + ''
				execute(@StrDeleteVisitor)
		end
	end

if @Type<>'search'
	begin
		delete #TempReportCheck Where fldDateSarResid< @DateSarResidAz
		delete #TempReportCheck Where fldDateSarResid> @DateSarResidTa
		delete #TempReportCheck Where fldDateDaryaft< @DateDaryaftAz
		delete #TempReportCheck Where fldDateDaryaft> @DateDaryaftTa
	end
else if @Type='search'
	begin
		execute('delete #TempReportCheck Where' + @ListGroupAshkhas )
	end

update #TempReportCheck set fldNameVasete=tblTafzili.fldSharheTafzili from tblTafzili Where #TempReportCheck.fldCodeVasete=tblTafzili.fldCodeTafzili
update #TempReportCheck set fldNameBankVagozari =tblKolMoin.fldSharheHesab from tblKolMoin Where tblKolMoin.fldCodeHesab =fldCodeBankVagozari
update #TempReportCheck set fldVaziatShow='واگذاری به ' + fldNameBankVagozari where fldVaziat='vagozari'
update #TempReportCheck set fldVaziatShow='وصول چک به شماره وصول ' + Convert(varchar,fldShomareVosool) where fldVaziat='vosool'
update #TempReportCheck set fldVaziat='foroosh', fldVaziatShow='واگذاری چک به ش پرداخت' + Convert(varchar,fldShomarePardakht) + ' به ' + tbl1.NameShakhs from 
		(SELECT        tblTafzili.fldSharheTafzili As NameShakhs, tblPardakht.fldShomarePardakht As ShomarePardakht FROM tblTafzili INNER JOIN tblPardakht ON tblTafzili.fldCodeTafzili = tblPardakht.fldCodeTafzili) As Tbl1
		Where tbl1.ShomarePardakht=fldShomarePardakht

update #TempReportCheck set fldVaziat ='' where fldVaziat is null
if @type='vosoolnashode'
	delete #TempReportCheck where fldVaziat<>''
if @type='vosool'
	begin
		delete #TempReportCheck where fldVaziat<>'vosool'
		update #TempReportCheck set fldNameHesabeVosool=tblKolMoin.fldSharheHesab from tblKolMoin 
			Where #TempReportCheck.fldCodeHesabeVosool=tblKolMoin.fldCodeHesab
	end
if @type='vagozari'
	delete #TempReportCheck where fldVaziat<>'vagozari'
if @type='Bargasht'
	delete #TempReportCheck where fldVaziat<>'Bargasht'
if @type='foroosh'
	delete #TempReportCheck where fldVaziat<>'foroosh'




update #TempReportCheck set fldNameGroupAshkhas=tblGroupAshkhas.fldGroupName from tblGroupAshkhas Where tblGroupAshkhas.fldGroupId=#TempReportCheck.fldCodeGroupAshkhas

Set @JameMablagh=(Select Sum(fldMablagh) from #TempReportCheck)
if @JameMablagh is null
	set @JameMablagh=0

Select ROW_NUMBER() OVER(ORDER BY fldDateDaryaft,ID ) AS Row,ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,
		fldCodeBank,fldNameBank,fldShobe,fldMablagh,fldDateDaryaft,fldDateDaryaftShow,
		fldShomareDaryaft,fldVaziat ,fldVaziatShow,fldShomarePardakht,
		fldShomareVosool,fldDateVosool,fldDateVosoolShow,fldSanadVosool,fldCodeHesabeVosool,fldNameHesabeVosool,fldCodeBankVagozari,fldNameBankVagozari,fldDateVagozariBeBank,fldDateVagozariBeBankShow,fldCodeVasete,fldNameVasete,fldNameGroupAshkhas
		 from  #TempReportCheck

END
GO

-- ===============================================
-- SP: [dbo].[z103ReportCheckDaryafti_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z103ReportCheckDaryafti_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z103ReportCheckDaryafti_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z103ReportCheckDaryafti_WithUserCode]
--چندزبانه
@Type nvarchar(20) ,
@ListGroupAshkhas nvarchar(4000)=null ,
@ListCodeAshkhas varchar(5000)=null,
@ListCodeVisitor varchar(5000)=null,
@DateSarResidAz bigint,
@DateSarResidTa bigint,
@DateDaryaftAz bigint,
@DateDaryaftTa bigint,
@userCode bigint,
@JameMablagh decimal(18,4) output
	
AS
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
BEGIN
	
SET NOCOUNT ON;


create table #TempReportCheck(

ID bigint,
fldShomareCheck nvarchar(30),
fldShomareHesab bigint,
fldShaba nvarchar(40),
fldSayad nvarchar(40),
fldCodeSahebeCheck Nvarchar(10) collate Persian_100_CI_AS,
fldSharheTafzili  Nvarchar(200) collate Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldDateSarResid bigint,
fldDateSarResidShow  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeBank int, 
fldNameBank Nvarchar(100) collate Persian_100_CI_AS, 
fldShobe Nvarchar(40) collate Persian_100_CI_AS,
fldMablagh decimal(18,4),
fldDateDaryaft bigint, 
fldDateDaryaftShow Nvarchar(20) collate Persian_100_CI_AS,
fldShomareDaryaft bigint,
fldVaziat  Nvarchar(15) collate Persian_100_CI_AS,
fldShomarePardakht bigint,
fldShomareVosool bigint,
fldDateVosool bigint,
fldDateVosoolShow nvarchar(15) collate Persian_100_CI_AS,
fldVaziatShow nvarchar(200)  collate Persian_100_CI_AS,
fldCodeDaryaftKonandeCheckeForokhte Nvarchar(10) collate Persian_100_CI_AS,
fldNameDaryaftKonandeCheckeForokhte  nvarchar(150)   collate Persian_100_CI_AS,
fldShomareOdat bigint,
fldShomareEnteghal bigint,
fldSanadVosool bigint,
fldCodeHesabeVosool bigint,
fldNameHesabeVosool nvarchar(200)  collate Persian_100_CI_AS,
fldCodeBankVagozari bigint,
fldNameBankVagozari nvarchar(200)  collate Persian_100_CI_AS,
fldDateVagozariBeBank bigint,
fldDateVagozariBeBankShow nvarchar(20)  collate Persian_100_CI_AS,
fldCodeVasete nvarchar(10)  collate Persian_100_CI_AS,
fldNameVasete nvarchar(200) collate Persian_100_CI_AS,
fldNameGroupAshkhas nvarchar(80) collate Persian_100_CI_AS,
fldTozihatCheck nvarchar(80) collate Persian_100_CI_AS,

)

--select * from tblCheckeDaryafti where fldShomareCheck='321654'
--if @type='all'
	begin

	--select * from tblCheckeDaryafti
		--براي انتقال چکهای ابتدای دوره
	--##################################################################################################################
	update tblCheckeDaryafti set fldVaziat='vagozari' where ISNUMERIC( fldDateVagozariBeBank )=1 and fldVaziat is null
	update tblCheckeDaryafti set fldVaziat='vosool' where ISNUMERIC( fldDateVosool )=1 and fldVaziat is null
	update tblCheckeDaryafti set fldVaziat='forooshecheck' where ISNUMERIC( fldShomarePardakht )=1 and fldVaziat is null
	update tblCheckeDaryafti set fldVaziat='Bargasht' where ISNUMERIC( fldDateBargasht )=1 and fldVaziat is null
	--##################################################################################################################

	Insert into  #TempReportCheck(ID,fldShomareCheck,fldShaba,fldSayad,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDateDaryaft,fldDateDaryaftShow,fldShomareDaryaft,fldVaziat,fldShomarePardakht,
			fldShomareVosool,fldDateVosool,fldDateVosoolShow,fldSanadVosool,fldShomareOdat,fldShomareEnteghal,fldCodeHesabeVosool,fldCodeBankVagozari,fldDateVagozariBeBank,fldDateVagozariBeBankShow,fldCodeVasete,fldTozihatCheck
			 )
		SELECT        dbo.tblCheckeDaryafti.ID,dbo.tblCheckeDaryafti.fldShomareCheck,dbo.tblCheckeDaryafti.fldShaba,dbo.tblCheckeDaryafti.fldSayad, dbo.tblCheckeDaryafti.fldShomareHesab,dbo.tblCheckeDaryafti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldCodeGroup,fldDateSarResid,
								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,fldDateDaryaft, 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,
								 fldShomareVosool,fldDateVosool,
								 SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVosool), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVosool), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVosool), 7, 2) AS fldDateVosoolShow,
								 dbo.tblCheckeDaryafti.fldSanadVosool,dbo.tblCheckeDaryafti.fldShomareOdat,fldShomareEnteghal, dbo.tblCheckeDaryafti.fldCodeHesabeVosool,dbo.tblCheckeDaryafti.fldCodeBankVagozari,fldDateVagozariBeBank,
								 SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVagozariBeBank), 1, 4) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVagozariBeBank), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar, tblCheckeDaryafti.fldDateVagozariBeBank), 7, 2) AS fldDateVagozariBeBankShow,tblCheckeDaryafti.fldVasete,tblCheckeDaryafti.fldsharhedaryaft
                         
		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									 
					order by tblCheckeDaryafti.fldDateSarResid,tblCheckeDaryafti.fldDateDaryaft
	end
--else if @type='vosoolnashode'
--	SELECT        dbo.tblCheckeDaryafti.ID,dbo.tblCheckeDaryafti.fldShomareCheck,dbo.tblCheckeDaryafti.fldShomareHesab,dbo.tblCheckeDaryafti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldDateSarResid,
--								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')
--					order by tblCheckeDaryafti.fldDateSarResid,tblCheckeDaryafti.fldDateDaryaft

update #TempReportCheck set fldSayad='' where fldsayad is Null
update #TempReportCheck set fldShaba='' where fldShaba is Null

if @type<>'search' 
	if @ListGroupAshkhas<>''
		begin
		declare @StrDeleteGroupAshkhas varchar(5000)
		set  @StrDeleteGroupAshkhas='delete from #TempReportCheck 
			where '+ @ListGroupAshkhas + ''
			execute(@StrDeleteGroupAshkhas)
		end


if @ListCodeAshkhas <>''
begin
	declare @StrDeleteAshkhas varchar(5000)
	set  @StrDeleteAshkhas='delete from #TempReportCheck 
		where fldCodeSahebeCheck NOT IN ('+ @ListCodeAshkhas +')'
		execute(@StrDeleteAshkhas)
end


if @ListCodeVisitor<>''
	begin
	if @ListCodeVisitor='-1' --لیست فاکتورهای بدون ویزیتور
		begin
			delete from #TempReportCheck where fldCodeVasete<>''
		end
	else
		begin
			declare @StrDeleteVisitor varchar(5000)
			set  @StrDeleteVisitor='delete from #TempReportCheck 
				where '+ @ListCodeVisitor + ''
				execute(@StrDeleteVisitor)
		end
	end



update #TempReportCheck set fldNameVasete=tblTafzili.fldSharheTafzili from tblTafzili Where #TempReportCheck.fldCodeVasete=tblTafzili.fldCodeTafzili
update #TempReportCheck set fldNameBankVagozari =tblKolMoin.fldSharheHesab from tblKolMoin Where tblKolMoin.fldCodeHesab =fldCodeBankVagozari
update #TempReportCheck set fldVaziatShow='واگذاری به ' + fldNameBankVagozari where fldVaziat='vagozari'
update #TempReportCheck set fldVaziatShow='وصول چک به شماره وصول ' + Convert(varchar,fldShomareVosool) where fldVaziat='vosool'
update #TempReportCheck set fldVaziat='forooshecheck', fldVaziatShow='واگذاری چک به ش پرداخت' + Convert(varchar,fldShomarePardakht) + ' به ' + tbl1.NameShakhs from 
		(SELECT        tblTafzili.fldSharheTafzili As NameShakhs, tblPardakht.fldShomarePardakht As ShomarePardakht FROM tblTafzili INNER JOIN tblPardakht ON tblTafzili.fldCodeTafzili = tblPardakht.fldCodeTafzili) As Tbl1
		Where tbl1.ShomarePardakht=fldShomarePardakht

update #TempReportCheck set fldNameDaryaftKonandeCheckeForokhte= tbl1.NameShakhs ,fldCodeDaryaftKonandeCheckeForokhte= tbl1.CodeTafzili from 
		(SELECT     tblTafzili.fldCodeTafzili as CodeTafzili ,  tblTafzili.fldSharheTafzili As NameShakhs, tblPardakht.fldShomarePardakht As ShomarePardakht FROM tblTafzili INNER JOIN tblPardakht ON tblTafzili.fldCodeTafzili = tblPardakht.fldCodeTafzili) As Tbl1
		Where tbl1.ShomarePardakht=fldShomarePardakht

update #TempReportCheck set fldCodeDaryaftKonandeCheckeForokhte= '' where fldCodeDaryaftKonandeCheckeForokhte is NUll
update #TempReportCheck set fldNameDaryaftKonandeCheckeForokhte= '' where fldNameDaryaftKonandeCheckeForokhte is NUll

update #TempReportCheck set fldVaziat ='' where fldVaziat is null


if @Type<>'search'
	begin
		delete #TempReportCheck Where fldDateSarResid< @DateSarResidAz
		delete #TempReportCheck Where fldDateSarResid> @DateSarResidTa
		delete #TempReportCheck Where fldDateDaryaft< @DateDaryaftAz
		delete #TempReportCheck Where fldDateDaryaft> @DateDaryaftTa
	end
else if @Type='search'
	begin
		update #TempReportCheck set fldVaziatShow='' where fldVaziatShow is NULL
		execute('delete #TempReportCheck Where' + @ListGroupAshkhas )
	end

if @type='vosoolnashode'
	delete #TempReportCheck where fldVaziat<>''
if @type='vosool'
	begin
		delete #TempReportCheck where fldVaziat<>'vosool'
		update #TempReportCheck set fldNameHesabeVosool=tblKolMoin.fldSharheHesab from tblKolMoin 
			Where #TempReportCheck.fldCodeHesabeVosool=tblKolMoin.fldCodeHesab
	end
if @type='vagozari'
	delete #TempReportCheck where fldVaziat<>'vagozari'
if @type='Bargasht'
	delete #TempReportCheck where fldVaziat<>'Bargasht'
if @type='foroosh'
	delete #TempReportCheck where fldVaziat<>'forooshecheck'
	
	


update #TempReportCheck set fldNameGroupAshkhas=tblGroupAshkhas.fldGroupName from tblGroupAshkhas Where tblGroupAshkhas.fldGroupId=#TempReportCheck.fldCodeGroupAshkhas

-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################

Set @JameMablagh=(Select Sum(fldMablagh) from #TempReportCheck where fldCodeSahebeCheck in (select code from @accessCodes))
if @JameMablagh is null
	set @JameMablagh=0

-- ##########################################################
-- #######Group Ashkhas Limitation###########################


Select ROW_NUMBER() OVER(ORDER BY fldDateSarResid,ID ) AS Row,fldShomareCheck, fldShomareHesab,fldShaba,fldSayad,fldCodeSahebeCheck,fldSharheTafzili,fldDateSarResidShow, fldCodeBank,fldNameBank,fldShobe,fldMablagh,fldDateDaryaftShow,fldShomareDaryaft,fldVaziatShow,fldCodeDaryaftKonandeCheckeForokhte,fldNameDaryaftKonandeCheckeForokhte
,fldTozihatCheck,fldShomarePardakht,fldShomareVosool,fldDateVosoolShow,fldSanadVosool,fldShomareOdat,fldShomareEnteghal,fldNameHesabeVosool,fldNameBankVagozari,fldDateVagozariBeBankShow,fldNameVasete,fldNameGroupAshkhas,fldDateSarResid,fldDateDaryaft,fldDateVosool,fldCodeHesabeVosool,fldCodeBankVagozari,fldDateVagozariBeBank,fldCodeVasete,fldVaziat,fldCodeGroupAshkhas,ID
		 from  #TempReportCheck
		 where fldCodeSahebeCheck in (select code from @accessCodes)

END
GO

-- ===============================================
-- SP: [dbo].[z104ChartForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.z104ChartForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z104ChartForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z104ChartForoosh]
	@year bigint
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;

	declare @strCodeMoinForoosh nvarchar(20),@JameForoosh bigint
    create table #tmpChartForoosh
		(
			fldNameMah nvarchar(20) COLLATE Persian_100_CI_AS,
			fldShomareMah bigint,
			fldJameForoosh bigint
		)
	
	
	execute CodeMoinHesab 'foroosh',@strCodeMoinForoosh output --'71301'
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0101' ) and Convert(bigint,  Convert(varchar, @year) + '0131' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
		
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('فروردین',1,@JameForoosh)
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0201' ) and Convert(bigint,  Convert(varchar, @year) + '0231' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
		
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('اردیبهشت',2,@JameForoosh)
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0301' ) and Convert(bigint,  Convert(varchar, @year) + '0331' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('خرداد',3,@JameForoosh)
	
	
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0401' ) and Convert(bigint,  Convert(varchar, @year) + '0431' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('تیر',4,@JameForoosh)
	
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0501' ) and Convert(bigint,  Convert(varchar, @year) + '0531' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('مرداد',5,@JameForoosh)
		
	
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0601' ) and Convert(bigint,  Convert(varchar, @year) + '0631' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('شهریور',6,@JameForoosh)
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0701' ) and Convert(bigint,  Convert(varchar, @year) + '0731' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('مهر',7,@JameForoosh)
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0801' ) and Convert(bigint,  Convert(varchar, @year) + '0831' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('آبان',8,@JameForoosh)
		
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0901' ) and Convert(bigint,  Convert(varchar, @year) + '0931' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('آذر',9,@JameForoosh)
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '1001' ) and Convert(bigint,  Convert(varchar, @year) + '1031' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('دی',10,@JameForoosh)
		
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '1101' ) and Convert(bigint,  Convert(varchar, @year) + '1131' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('بهمن',11,@JameForoosh)	
		
		
	set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '1201' ) and Convert(bigint,  Convert(varchar, @year) + '1231' ))
	if ISNUMERIC(@JameForoosh)=0 
		set @JameForoosh=0
	insert into #tmpChartForoosh
		(fldNameMah,fldShomareMah,fldJameForoosh)
		Values
		('اسفند',12,@JameForoosh)
		
	select fldNameMah,fldShomareMah,fldJameForoosh from #tmpChartForoosh		
END
GO

-- ===============================================
-- SP: [dbo].[z105ChartForooshVizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.z105ChartForooshVizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z105ChartForooshVizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z105ChartForooshVizitor]
	@year bigint,
	@KolMahiane int,
	@DateAz bigint,
	@DateTa bigint
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;

	declare @strCodeMoinForoosh nvarchar(20),@JameForoosh bigint
    create table #tmpChartForoosh
		(
			fldCodeVasete bigint,
			fldNameVizitor nvarchar(200) COLLATE Persian_100_CI_AS,			
			fldJameForoosh bigint
		)
	
	if @KolMahiane=0 
		insert into #tmpChartForoosh
			(fldJameForoosh,fldCodeVasete)
		SELECT     SUM(fldMablaghKhales) AS Expr1, fldCodeVasete
			FROM         tblRizeForoosh
			WHERE     (fldCodeVasete <> 0) and substring(convert(nvarchar,flddate),1,4)=@year
			GROUP BY fldCodeVasete
	else
		insert into #tmpChartForoosh
			(fldJameForoosh,fldCodeVasete)
		SELECT     SUM(fldMablaghKhales) AS Expr1, fldCodeVasete
			FROM         tblRizeForoosh
			WHERE     (fldCodeVasete <> 0)  and fldDate between   @DateAz and @DateTa --CONVERT(bigint, Convert(varchar,@year ) + Convert(varchar,@KolMahiane) + '01') And CONVERT(bigint, Convert(varchar,@year ) + Convert(varchar,@KolMahiane) + '31')
			GROUP BY fldCodeVasete
		
	update #tmpChartForoosh set fldNameVizitor=tblTafzili.fldSharheTafzili from tblTafzili where #tmpChartForoosh.fldCodeVasete=tblTafzili.fldCodeTafzili
	
	select fldCodeVasete,fldNameVizitor,fldJameForoosh from #tmpChartForoosh
	--execute CodeMoinHesab 'foroosh',@strCodeMoinForoosh output --'71301'
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0101' ) and Convert(bigint,  Convert(varchar, @year) + '0131' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
		
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('فروردین',1,@JameForoosh)
		
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0201' ) and Convert(bigint,  Convert(varchar, @year) + '0231' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
		
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('اردیبهشت',2,@JameForoosh)
		
		
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0301' ) and Convert(bigint,  Convert(varchar, @year) + '0331' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('خرداد',3,@JameForoosh)
	
	
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0401' ) and Convert(bigint,  Convert(varchar, @year) + '0431' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('تیر',4,@JameForoosh)
	
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0501' ) and Convert(bigint,  Convert(varchar, @year) + '0531' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('مرداد',5,@JameForoosh)
		
	
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0601' ) and Convert(bigint,  Convert(varchar, @year) + '0631' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('شهریور',6,@JameForoosh)
		
		
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0701' ) and Convert(bigint,  Convert(varchar, @year) + '0731' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('مهر',7,@JameForoosh)
		
		
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0801' ) and Convert(bigint,  Convert(varchar, @year) + '0831' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('آبان',8,@JameForoosh)
		
		
		
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '0901' ) and Convert(bigint,  Convert(varchar, @year) + '0931' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('آذر',9,@JameForoosh)
		
		
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '1001' ) and Convert(bigint,  Convert(varchar, @year) + '1031' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('دی',10,@JameForoosh)
		
		
		
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '1101' ) and Convert(bigint,  Convert(varchar, @year) + '1131' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('بهمن',11,@JameForoosh)	
		
		
	--set @JameForoosh=(Select  SUM(fldBestankar-fldBedehkar) As SumForoosh from tblSodooreSanad	Where fldMoinKamel=@strCodeMoinForoosh And flddate between Convert(bigint, Convert(varchar, @year) + '1201' ) and Convert(bigint,  Convert(varchar, @year) + '1231' ))
	--if ISNUMERIC(@JameForoosh)=0 
	--	set @JameForoosh=0
	--insert into #tmpChartForoosh
	--	(fldNameMah,fldShomareMah,fldJameForoosh)
	--	Values
	--	('اسفند',12,@JameForoosh)
		
	--select fldNameMah,fldShomareMah,fldJameForoosh from #tmpChartForoosh		
END
GO

-- ===============================================
-- SP: [dbo].[z106ChartVarizVizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.z106ChartVarizVizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z106ChartVarizVizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z106ChartVarizVizitor]
	@year bigint,
	@KolMahiane int,
	@DateAz bigint,
	@DateTa bigint
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;

	declare @strCodeMoinVariz nvarchar(20),@JameVariz bigint
    create table #tmpChartVariz
		(
			fldCodeVasete bigint,
			fldNameVizitor nvarchar(200) COLLATE Persian_100_CI_AS,			
			fldJameVariz bigint
		)

	--واسطه هایی که حذف شدن
	update tblSodooreSanad set fldvasete=NULL where fldVasete not in (Select fldCodeTafzili from tblTafzili where fldNoeVizitor=1 or fldNoeVizitor=2)
	update tblCheckeDaryafti set fldVasete=NULL where fldVasete not in (Select fldCodeTafzili from tblTafzili where fldNoeVizitor=1 or fldNoeVizitor=2)


	declare @KolBank nvarchar(50),@KolSandoogh nvarchar(50)
		
	execute CodeKolHesab 'bank',@KolBank output
	execute CodeKolHesab 'sandoogh',@KolSandoogh output
	
	if @KolMahiane=0 
	begin
		insert into #tmpChartVariz
			(fldJameVariz,fldCodeVasete)
		SELECT     SUM(fldBedehkar-fldBestankar) AS Expr1,fldVasete
			FROM         tblSodooreSanad
			WHERE     (fldVasete <> 0)   and (fldCodekol=@KolBank or fldCodekol=@KolSandoogh)
			GROUP BY fldVasete
			

				insert into #tmpChartVariz
			(fldJameVariz,fldCodeVasete)
		SELECT     SUM(fldMablagh) AS Expr1,  CONVERT(bigint,fldVasete)AS fldCodeVasete
			FROM         tblCheckeDaryafti
			WHERE     (CONVERT(bigint,fldVasete) <> 0 and ISNUMERIC(fldShomareVosool)=1)
			GROUP BY CONVERT(bigint,fldVasete)
end
	else
	begin
		insert into #tmpChartVariz
			(fldJameVariz,fldCodeVasete)
		SELECT     SUM(fldBedehkar-fldBestankar) AS Expr1, fldVasete
			FROM         tblSodooreSanad
			WHERE     (fldVasete <> 0) and (fldCodekol=@KolBank or fldCodekol=@KolSandoogh) and fldDate between   CONVERT(bigint, @DateAz) and CONVERT(bigint, @DateTa)
			GROUP BY fldVasete

			
		--insert into #tmpChartVariz
		--	(fldJameVariz,fldCodeVasete)
		--SELECT     SUM(fldMablagh) AS Expr1,  CONVERT(bigint,fldVasete)AS fldCodeVasete
		--	FROM         tblCheckeDaryafti
		--	WHERE     (CONVERT(bigint,fldVasete) <> 0 and ISNUMERIC(fldShomareVosool)=1) and fldDateVosool between   @DateAz and @DateTa
		--	GROUP BY CONVERT(bigint,fldVasete)
	end
	update #tmpChartVariz set fldNameVizitor=tblTafzili.fldSharheTafzili from tblTafzili where #tmpChartVariz.fldCodeVasete=tblTafzili.fldCodeTafzili 
	
	select fldCodeVasete,fldNameVizitor,Sum(fldJameVariz) as fldJameVariz from #tmpChartVariz
		group by fldCodeVasete,fldNameVizitor
	
END
GO

-- ===============================================
-- SP: [dbo].[z106CountKalaForooshBadAzFee0]
-- ===============================================
IF OBJECT_ID(N'dbo.z106CountKalaForooshBadAzFee0', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z106CountKalaForooshBadAzFee0] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z106CountKalaForooshBadAzFee0]
	@CodeKala bigint,
	@CodeTafzili bigint,
	@CountTedad bigint output
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	declare @MaxIDFee0 bigint
	set @MaxIdFee0 = (Select MAX(Id) from tblRizeForoosh Where fldCodeKala=@CodeKala and fldCodeTafsili=@CodeTafzili and fldFeeJoz=0)
	if @MaxIdFee0  is null
		set @MaxIdFee0 =0
    -- Insert statements for procedure here
	set @CountTedad=(Select Sum(fldTedadJoz) as cnt from tblrizeforoosh where fldCodeKala=@codekala and fldCodeTafsili=@CodeTafzili and ID>@MaxIDFee0)
	if @CountTedad is null
		set @CountTedad=0
END
GO

-- ===============================================
-- SP: [dbo].[z107InsertInfoInTolid]
-- ===============================================
IF OBJECT_ID(N'dbo.z107InsertInfoInTolid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z107InsertInfoInTolid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z107InsertInfoInTolid]
(
	@Flag nvarchar(15),
	@HazineTabdil bigint,
	--@dtCheckDaryafti tblCheckDaryafti readonly
	@RizeTolid tpRizeTolidNewNew3 readonly,
	@NoeKhata nvarchar(20) output
)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	--insert into  tblRizeTolid  (fldShomareSanad, fldShomareTolid, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
 --                     fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
 --                     fldDate, fldTime)
	--		Select    fldShomareSanad, fldShomareTolid, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
 --                     fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
 --                     fldDate, fldTime output from @dtCheckDaryafti;
			
		begin transaction transact
		begin try
		
			if @Flag='insert'
				begin
					declare @ShomareTolid2 bigint,@cntTekrari bigint,@ShomareTolidAsli bigint
					set @ShomareTolid2=(Select  top(1) fldShomareTolid from @RizeTolid)
					
					set @cntTekrari=(select COUNT(fldShomaretolid) from tblRizeTolid Where fldShomareTolid=@ShomareTolid2)
					
					--#####################################################
					--اگر شماره تولید تکراری باشد خودش جدید معرفی میکنه
					set @ShomareTolidAsli=(Select Top(1) fldShomareTolid from @RizeTolid )
					if @cntTekrari>0
						set @ShomareTolidAsli=(Select MAX(fldShomareTolid)+1 as Max from tblRizeTolid )
					--#####################################################
					
																			
					Insert into  tblRizeTolid (fldShomareSanad, fldShomareTolid, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
						fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
						fldDate, fldTime,fldDarsdeTakhfif,fldMablagheTakhfif,fldHazineTabdil,fldDateEngheza,fldBatchNumber)
					Select fldShomareSanad, @ShomareTolidAsli, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
							  fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
							  fldDate, fldTime,fldDarsdeTakhfif,fldMablagheTakhfif,@HazineTabdil,fldDateEngheza,fldBatchNumber output from @RizeTolid;	
							  
					set @NoeKhata='insert'
				end
			else
				begin
					declare @ShomareTolid bigint
					set @ShomareTolid=(Select  top(1) fldShomareTolid from @RizeTolid)
						

						
					delete tblRizeTolid Where fldShomareTolid=@ShomareTolid
					
					Insert into  tblRizeTolid (fldShomareSanad, fldShomareTolid, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
						fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
						fldDate, fldTime,fldDarsdeTakhfif,fldMablagheTakhfif,fldHazineTabdil,fldDateEngheza,fldBatchNumber)
					Select fldShomareSanad, @ShomareTolid, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
							  fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
							  fldDate, fldTime,fldDarsdeTakhfif,fldMablagheTakhfif,@HazineTabdil,fldDateEngheza,fldBatchNumber output from @RizeTolid;	
					
					set @NoeKhata='update'
				end
			commit transaction
		end try

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

		end catch	

		
    -- Insert statements for procedure here	
END
GO

-- ===============================================
-- SP: [dbo].[z107MiangineMozoodekala]
-- ===============================================
IF OBJECT_ID(N'dbo.z107MiangineMozoodekala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z107MiangineMozoodekala] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z107MiangineMozoodekala]
	@fldCodeKala bigint,
	@fldTarikhAz bigint,
	@fldTarikhTa bigint
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 #tmpMiangin
		(
			fldCodeKala bigint,
			fldTedad int,			
			fldMablagh decimal,
			fldTarikh bigint
		)

		insert into #tmpMiangin(fldCodeKala,fldTedad,fldMablagh,fldTarikh)
		select fldCodeKala,fldTedadJoz,fldFeeJoz,fldDate from tblRizeKharid
		where fldCodeKala=@fldCodeKala and fldDate between @fldTarikhAz and @fldTarikhTa

		insert into #tmpMiangin(fldCodeKala,fldTedad,fldMablagh,fldTarikh)
		select fldCodeKala,fldTedadJozNahaei,fldFeeJoz,fldDate from tblRizeTolid
		where fldCodeKala=@fldCodeKala and fldDate between @fldTarikhAz and @fldTarikhTa and fldType='mahsool'

		insert into #tmpMiangin(fldCodeKala,fldTedad,fldMablagh,fldTarikh)
		select fldCodeKala,fldTedadJoz,fldFeeJoz,fldDate from tblRizeBargashtAzForoosh
		where fldCodeKala=@fldCodeKala and fldDate between @fldTarikhAz and @fldTarikhTa

		select ROW_NUMBER()OVER(ORDER BY fldTarikh) as fldRadif,fldCodeKala,fldTedad,fldMablagh,fldTarikh from #tmpMiangin order by fldTarikh
	
	
END
GO

-- ===============================================
-- SP: [dbo].[z108GardesheKala]
-- ===============================================
IF OBJECT_ID(N'dbo.z108GardesheKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z108GardesheKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z108GardesheKala]
	@userCode bigint,
	@ListGroupKala varchar(5000)=null
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 #tmpGardesheKala
		(
			CodeKala bigint,
			CodeGroup bigint,
			CodeAnbar bigint,
			NameGroup nvarchar(100) collate Persian_100_CI_AS,
			NameKala nvarchar(100) collate Persian_100_CI_AS,
			NameAnbar nvarchar(100) collate Persian_100_CI_AS,
			TedadDarKarton bigint,
			MablagheEbteda bigint,
			TedadeEbteda bigint,
			TedadKartonEbteda nvarchar(100) collate Persian_100_CI_AS,

			MablagheKharid bigint,
			TedadeKharid bigint,
			TedadKartonKharid nvarchar(100) collate Persian_100_CI_AS,
			TedadMoghayerat bigint,

			MablagheBargashtAzKharid bigint,
			TedadeBargashtAzKharid bigint,
			TedadKartonBargashtAzKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheKhalesKharid bigint,
			TedadeKhalesKharid bigint,
			TedadKartonKhalesKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheForoosh bigint,
			TedadeForoosh bigint,
			TedadeKartonForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablagheBargashtAzForoosh bigint,
			TedadeBargashtAzForoosh bigint,
			TedadeKartonBargashtAzForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablagheKhalesForoosh bigint,
			TedadeKhalesForoosh bigint,
			TedadKartonKhalesForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablaghePayan bigint,
			TedadePayan bigint,
			TedadeKartonPayan nvarchar(100) collate Persian_100_CI_AS,
			SoodeKala bigint,
			fldTedadSefaresh bigint
		)

-- Group Kala access
 Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA')
  if @value = 'True'
  Begin -- Limitation Active  
	-- Get All AccessKala
	declare @accesskala table(code bigint)
	insert into @accesskala 
	exec [ZSP_GetKalaAccesses] @userCode


		insert into #tmpGardesheKala
			(CodeKala,CodeGroup,NameKala,TedadDarKarton,fldTedadSefaresh)
			Select  fldCodeKala,fldCodeGroup,fldNameKala,fldTedadJoz,0 as fldTedadSefaresh 
				from  tblKala
				-- add kala access limitation
				where tblKala.fldCodeGroup in (select code from @accesskala)

end
else begin

insert into #tmpGardesheKala
			(CodeKala,CodeGroup,NameKala,TedadDarKarton,fldTedadSefaresh)
			Select  fldCodeKala,fldCodeGroup,fldNameKala,fldTedadJoz,0 as fldTedadSefaresh
				from  tblKala

end


		if @ListGroupKala<>''
		   begin
		     declare @StrDeleteGroupKala varchar(5000)
		       set  @StrDeleteGroupKala='delete from #tmpGardesheKala 
		            where '+ @ListGroupKala + ''
					execute(@StrDeleteGroupKala)
		   end
		--update #tmpGardesheKala set TedadeEbteda=Sum(tblRizeKharid.fldTedadeJoz) from tblRizeKharid where #tmpGardesheKala.CodeKala=tblRizeKharid.fldCodeKala group by tblRizeKharid.fldCodeKala

		update           #tmpGardesheKala
			set NameGroup = tblGroupKala.fldGroupName from tblGroupKala Where CodeGroup=tblGroupKala.fldGroupId

		--####ابتدای دوره####
		update           #tmpGardesheKala
			set tedadeEbteda=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='mojodi_ebteda_doreh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheEbteda=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldFeeKol) as Sum1 from tblRizekharid Where fldType='mojodi_ebteda_doreh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 
			--mojodi_ebteda_doreh



		--کارتن و عدد
		update #tmpGardesheKala Set TedadKartonEbteda=Convert(varchar,floor(tedadeEbteda / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeEbteda, TedadDarKarton) } ) 
			where TedadDarKarton>0
		--######################
		--####تعداد مغایرت####
		update           #tmpGardesheKala
			set TedadMoghayerat=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='Moghayrat' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		update           #tmpGardesheKala
			set TedadMoghayerat-=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeForoosh Where fldType='Moghayrat' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 
		--######خرید#####
		update           #tmpGardesheKala
			set tedadekharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='kharid' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set Mablaghekharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizekharid Where fldType='kharid' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		--کارتن و عدد
		update #tmpGardesheKala Set TedadKartonkharid=Convert(varchar,floor(TedadeKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeKharid, TedadDarKarton) } ) 
			where TedadDarKarton>0
		--#######################

		--######برگشت از خرید#####
		update           #tmpGardesheKala
			set tedadeBargashtAzkharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeBargashtAzkharid Where fldType='bargashtazkharid' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheBargashtAzKharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeBargashtAzkharid Where fldType='bargashtazkharid' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		--کارتن و عدد
		update #tmpGardesheKala Set TedadKartonBargashtAzkharid=Convert(varchar,floor(TedadeBargashtAzKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeBargashtAzKharid, TedadDarKarton) } ) 
			where TedadDarKarton>0
		--#######################


		--######فروش#####
		update           #tmpGardesheKala
			set TedadeForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeForoosh Where fldType='Foroosh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeForoosh Where fldType='Foroosh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		--کارتن و عدد
		update #tmpGardesheKala Set TedadeKartonForoosh=Convert(varchar,floor(TedadeForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeForoosh, TedadDarKarton) } ) 
			where TedadDarKarton>0
		--#######################

		--######برگشت از فروش#####
		update           #tmpGardesheKala
			set TedadeBargashtAzForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeBargashtAzForoosh Where fldType='bargashtazforoosh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheBargashtAzForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeBargashtAzForoosh Where fldType='bargashtazforoosh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		--کارتن و عدد
		update #tmpGardesheKala Set TedadeKartonForoosh=Convert(varchar,floor(TedadeForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeForoosh, TedadDarKarton) } ) 
			where TedadDarKarton>0

			--------bm
			
			update #tmpGardesheKala 
			set fldTedadSefaresh= iif(tbl1.fldTedadSefaresh=NULL,0,tbl1.fldTedadSefaresh) from  (Select fldCodeKala,fldTedadSefaresh from tblSefareshGardeshKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		--#######################

		update           #tmpGardesheKala
			set TedadeEbteda=0 Where TedadeEbteda is null  
		update           #tmpGardesheKala
			set TedadeKharid=0 Where TedadeKharid is null
		update           #tmpGardesheKala
			set TedadeBargashtAzKharid=0 Where TedadeBargashtAzKharid is null
		update           #tmpGardesheKala
			set TedadeForoosh=0 Where TedadeForoosh is null
		update           #tmpGardesheKala
			set TedadeBargashtAzForoosh=0 Where TedadeBargashtAzForoosh is null
		update           #tmpGardesheKala
			set MablagheEbteda=0 Where MablagheEbteda is null
		update           #tmpGardesheKala
			set MablagheKharid=0 Where MablagheKharid is null
		update           #tmpGardesheKala
			set MablagheBargashtAzKharid=0 Where MablagheBargashtAzKharid is null
		update           #tmpGardesheKala
			set MablagheForoosh=0 Where MablagheForoosh is null
		update           #tmpGardesheKala
			set MablagheBargashtAzForoosh=0 Where MablagheBargashtAzForoosh is null
		update           #tmpGardesheKala
			set MablaghePayan=0 Where MablaghePayan is null
		update           #tmpGardesheKala
			set TedadMoghayerat=0 Where TedadMoghayerat is null

		--######خالص خرید#######
		update           #tmpGardesheKala
			set TedadeKhalesKharid=TedadeKharid-TedadeBargashtAzKharid
		update #tmpGardesheKala Set TedadKartonKhalesKharid=Convert(varchar,floor(TedadeKhalesKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalesKharid, TedadDarKarton) } ) 
			where TedadDarKarton>0

		update #tmpGardesheKala Set MablagheKhalesKharid=MablagheKharid-MablagheBargashtAzKharid

		--######خالص فروش#######
		update           #tmpGardesheKala
			set TedadeKhalesForoosh=TedadeForoosh-TedadeBargashtAzForoosh
		update #tmpGardesheKala Set TedadKartonKhalesForoosh=Convert(varchar,floor(TedadeKhalesForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalesForoosh, TedadDarKarton) } ) 
			where TedadDarKarton>0

		update #tmpGardesheKala Set MablagheKhalesForoosh=MablagheForoosh-MablagheBargashtAzForoosh
		--######پایان دوره#####
		update           #tmpGardesheKala
			set tedadePayan=TedadeEbteda+TedadeKharid+TedadeBargashtAzForoosh +TedadMoghayerat -TedadeForoosh-TedadeBargashtAzKharid
		update #tmpGardesheKala
			set MablaghePayan=(MablagheEbteda+MablagheKharid)/(TedadeEbteda+TedadeKharid)*tedadePayan
			where TedadeEbteda+TedadeKharid>0
		--کارتن و عدد
		update #tmpGardesheKala Set TedadeKartonPayan=Convert(varchar,floor(TedadePayan/ TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadePayan, TedadDarKarton) } ) 
			where TedadDarKarton>0

		--#######################

		--####انتقال بین انبار و تولید کنترل شود#######


		update #tmpGardesheKala set NameGroup='' where NameGroup is NULL
		update #tmpGardesheKala set TedadKartonEbteda='' where TedadKartonEbteda is NULL

		Select ROW_NUMBER() OVER(ORDER BY CodeKala ) AS Row, CodeKala,NameGroup,NameKala,TedadDarKarton,TedadeEbteda,TedadKartonEbteda,MablagheEbteda,
			TedadeKharid,TedadKartonKharid,MablagheKharid,TedadeBargashtAzKharid,TedadKartonBargashtAzKharid,MablagheBargashtAzKharid,TedadeKhalesKharid,TedadKartonKhalesKharid,MablagheKhalesKharid,TedadeForoosh,TedadeKartonForoosh,MablagheForoosh,TedadeBargashtAzForoosh,TedadeKartonBargashtAzForoosh,MablagheBargashtAzForoosh,TedadeKhalesForoosh,TedadKartonKhalesForoosh,MablagheKhalesForoosh,TedadePayan,TedadeKartonPayan,MablaghePayan,fldTedadSefaresh
		from #tmpGardesheKala
	
END
GO

-- ===============================================
-- SP: [dbo].[z109InsertInfoInFormooleTolid]
-- ===============================================
IF OBJECT_ID(N'dbo.z109InsertInfoInFormooleTolid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z109InsertInfoInFormooleTolid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z109InsertInfoInFormooleTolid]
(
	@Flag nvarchar(15),
	@NameFormool nvarchar(100),
	@HazineTabdil bigint,
	--@dtCheckDaryafti tblCheckDaryafti readonly
	@RizeFormooleTolid tpRizeTolid3 readonly,
	@NoeKhata nvarchar(20) output
)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	--insert into  tblRizeTolid  (fldShomareSanad, fldShomareTolid, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
 --                     fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
 --                     fldDate, fldTime)
	--		Select    fldShomareSanad, fldShomareTolid, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
 --                     fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
 --                     fldDate, fldTime output from @dtCheckDaryafti;
			
		begin transaction transact
		begin try
		
			if @Flag='insert'
				begin
					declare @ShomareTolid2 bigint,@cntTekrari bigint,@ShomareTolidAsli bigint
					set @ShomareTolid2=(Select  top(1) fldShomareTolid from @RizeFormooleTolid)
					
					set @cntTekrari=(select COUNT(fldShomaretolid) from tblRizeFormooleTolid Where fldShomareTolid=@ShomareTolid2)
					
					--#####################################################
					--اگر شماره تولید تکراری باشد خودش جدید معرفی میکنه
					set @ShomareTolidAsli=(Select Top(1) fldShomareTolid from @RizeFormooleTolid )
					if @cntTekrari>0
						set @ShomareTolidAsli=(Select MAX(fldShomareTolid)+1 as Max from tblRizeFormooleTolid )
					--#####################################################
					
																			
					Insert into  tblRizeFormooleTolid (fldNameFormool, fldShomareSanad, fldShomareTolid, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
						fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
						fldDate, fldTime,fldDarsdeTakhfif,fldMablagheTakhfif,fldHazineTabdil)
					Select @NameFormool,fldShomareSanad, @ShomareTolidAsli, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
							  fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
							  fldDate, fldTime,fldDarsdeTakhfif,fldMablagheTakhfif,@HazineTabdil output from @RizeFormooleTolid;	
							  
					set @NoeKhata='insert'
				end
			else
				begin
					declare @ShomareTolid bigint
					set @ShomareTolid=(Select  top(1) fldShomareTolid from @RizeFormooleTolid)
						

						
					delete tblRizeFormooleTolid Where fldShomareTolid=@ShomareTolid
					
					Insert into  tblRizeFormooleTolid (fldNameFormool, fldShomareSanad, fldShomareTolid, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
						fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
						fldDate, fldTime,fldDarsdeTakhfif,fldMablagheTakhfif,fldHazineTabdil)
					Select @NameFormool,fldShomareSanad, @ShomareTolid, fldCodeUser, fldRadif, fldCodeAnbar, fldCodeKala, fldSharhKala, fldTedadCartonAvalie, fldTedadJozAvalie, 
							  fldTedadCartonNahaei, fldTedadJozNahaei, fldFeeJoz, fldFeeYekCarton, fldFeeKol, fldFeeVahed1BadAzTakhfif, fldFeeVahed2BadAzTakhfif, fldMablaghKhales, fldType, 
							  fldDate, fldTime,fldDarsdeTakhfif,fldMablagheTakhfif,@HazineTabdil output from @RizeFormooleTolid;	
					
					set @NoeKhata='update'
				end
			commit transaction
		end try

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

		end catch	

		
    -- Insert statements for procedure here	
END
GO

-- ===============================================
-- SP: [dbo].[z109MandeMarakez]
-- ===============================================
IF OBJECT_ID(N'dbo.z109MandeMarakez', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z109MandeMarakez] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z109MandeMarakez]
	@CodeMarkaz nvarchar(50)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
		--SELECT        SUM(fldBedehkar - fldBestankar) AS SumMande, fldCodeTafzili
		--		FROM            tblSodooreSanad
		--		WHERE        (ISnumeric(fldCodeMarkaz1) = 1) AND (isnumeric(fldCodeTafzili) = 1) and fldCodeMarkaz1=@CodeMarkaz
		--		GROUP BY fldCodeMarkaz1, fldCodeTafzili
		--		ORDER BY fldCodeTafzili


		SELECT        SUM(tblSodooreSanad.fldBedehkar - tblSodooreSanad.fldBestankar) AS SumMande, tblSodooreSanad.fldCodeTafzili, tblTafzili.fldSharheTafzili
			FROM            tblSodooreSanad INNER JOIN
									 tblTafzili ON tblSodooreSanad.fldCodeTafzili = tblTafzili.fldCodeTafzili
			WHERE        (ISnumeric(tblSodooreSanad.fldCodeMarkaz1) = 1) AND (isnumeric(tblSodooreSanad.fldCodeTafzili) = 1) AND (fldCodeMarkaz1=@CodeMarkaz)
			GROUP BY tblSodooreSanad.fldCodeMarkaz1, tblSodooreSanad.fldCodeTafzili, tblTafzili.fldSharheTafzili



END
GO

-- ===============================================
-- SP: [dbo].[z109ReportCheckPardakhti]
-- ===============================================
IF OBJECT_ID(N'dbo.z109ReportCheckPardakhti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z109ReportCheckPardakhti] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z109ReportCheckPardakhti]
@Type nvarchar(20),
@fldShomareCheck bigint,
@ListGroupAshkhas varchar(5000)=null,
@ListCodeAshkhas varchar(5000)=null,
@ListCodeBank varchar(5000)=null,
@DateSarResidAz bigint,
@DateSarResidTa bigint,
@DatePardakhtAz bigint,
@DatePardakhtTa bigint,
@DatePassAz bigint,
@DatePassTa bigint,
@JameMablagh bigint output

	
AS
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
BEGIN
	
SET NOCOUNT ON;


create table #TempReportCheckPardakht(

ID bigint,
fldShomareCheck bigint,
fldShomareHesab bigint,
fldCodeSahebeCheck Nvarchar(10) collate Persian_100_CI_AS,
fldSharheTafzili  Nvarchar(200) collate Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldDateSarResid bigint,
fldDateSarResidShow  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeBank int, 
fldNameBank Nvarchar(100) collate Persian_100_CI_AS, 
fldShobe Nvarchar(40) collate Persian_100_CI_AS,
fldMablagh decimal(18,0),
fldDatePardakht bigint, 
fldDatePardakhtShow Nvarchar(20) collate Persian_100_CI_AS,
fldVaziat  Nvarchar(15) collate Persian_100_CI_AS,
fldShomarePardakht bigint,
fldShomarePass bigint,
fldDatePass bigint,
fldDatePassShow nvarchar(15) collate Persian_100_CI_AS,
fldVaziatShow nvarchar(50)  collate Persian_100_CI_AS,
fldNameGroupAshkhas nvarchar(80) collate Persian_100_CI_AS

)

if @type='all' or  @type='search'
	begin

	Insert into  #TempReportCheckPardakht(ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili
	,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDatePardakht,fldDatePardakhtShow
			,fldShomarePardakht,fldShomarePass,fldDatePass,fldDatePassShow
			 )
		SELECT        dbo.tblCheckePardakhti.ID,dbo.tblCheckePardakhti.fldShomareCheck,dbo.tblCheckePardakhti.fldShomareHesab
		             ,dbo.tblCheckePardakhti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldCodeGroup,tblCheckePardakhti.fldDateSarResid,
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
								 dbo.tblCheckePardakhti.fldCodeBank,dbo.tblKolMoin.fldSharheHesab, dbo.tblCheckePardakhti.fldShobe, 
								 dbo.tblCheckePardakhti.fldMablagh,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,fldShomarePass,fldDatePass,
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 1, 4) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 5, 2) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 7, 2) AS fldDatePassShow

							
							
                         
		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									 
					order by tblCheckePardakhti.fldDateSarResid,tblCheckePardakhti.fldDatePardakht
	end
	if @type='Pass'
	begin
		Insert into  #TempReportCheckPardakht(ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili
	,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDatePardakht,fldDatePardakhtShow
			,fldShomarePardakht,fldShomarePass,fldDatePass,fldDatePassShow
			 )
		SELECT        dbo.tblCheckePardakhti.ID,dbo.tblCheckePardakhti.fldShomareCheck,dbo.tblCheckePardakhti.fldShomareHesab
		             ,dbo.tblCheckePardakhti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldCodeGroup,tblCheckePardakhti.fldDateSarResid,
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
								 dbo.tblCheckePardakhti.fldCodeBank,dbo.tblKolMoin.fldSharheHesab, dbo.tblCheckePardakhti.fldShobe, 
								 dbo.tblCheckePardakhti.fldMablagh,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,fldShomarePass,fldDatePass,
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 1, 4) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 5, 2) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 7, 2) AS fldDatePassShow

							
							
                         
		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 ISNUMERIC(fldShomarePass)=1					 
					order by tblCheckePardakhti.fldDateSarResid,tblCheckePardakhti.fldDatePardakht
	end
if @type='PassNashode'
begin
Insert into  #TempReportCheckPardakht(ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili
	,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDatePardakht,fldDatePardakhtShow
			,fldShomarePardakht,fldShomarePass,fldDatePass,fldDatePassShow
			 )
		SELECT        dbo.tblCheckePardakhti.ID,dbo.tblCheckePardakhti.fldShomareCheck,dbo.tblCheckePardakhti.fldShomareHesab
		             ,dbo.tblCheckePardakhti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldCodeGroup,tblCheckePardakhti.fldDateSarResid,
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
								 dbo.tblCheckePardakhti.fldCodeBank,dbo.tblKolMoin.fldSharheHesab, dbo.tblCheckePardakhti.fldShobe, 
								 dbo.tblCheckePardakhti.fldMablagh,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,fldShomarePass,fldDatePass,
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 1, 4) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 5, 2) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 7, 2) AS fldDatePassShow

							
							
                         
		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  ISNUMERIC(fldShomarePass)<>1					 
					order by tblCheckePardakhti.fldDateSarResid,tblCheckePardakhti.fldDatePardakht
	--delete #TempReportCheckPardakht where fldShomarePass=2
	end

	if @type='BazPasShode'
begin
Insert into  #TempReportCheckPardakht(ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili
	,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDatePardakht,fldDatePardakhtShow
			,fldShomarePardakht,fldShomarePass,fldDatePass,fldDatePassShow
			 )
		SELECT        dbo.tblCheckePardakhti.ID,dbo.tblCheckePardakhti.fldShomareCheck,dbo.tblCheckePardakhti.fldShomareHesab
		             ,dbo.tblCheckePardakhti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldCodeGroup,tblCheckePardakhti.fldDateSarResid,
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
								 dbo.tblCheckePardakhti.fldCodeBank,dbo.tblKolMoin.fldSharheHesab, dbo.tblCheckePardakhti.fldShobe, 
								 dbo.tblCheckePardakhti.fldMablagh,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,fldShomarePass,fldDatePass,
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 1, 4) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 5, 2) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 7, 2) AS fldDatePassShow

							
							
                         
		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  ISNUMERIC(fldShomareBazPas)=1					 
					order by tblCheckePardakhti.fldDateSarResid,tblCheckePardakhti.fldDatePardakht
	--delete #TempReportCheckPardakht where fldShomarePass=2
	end
--else if @type='vosoolnashode'
--	SELECT        dbo.tblCheckeDaryafti.ID,dbo.tblCheckeDaryafti.fldShomareCheck,dbo.tblCheckeDaryafti.fldShomareHesab,dbo.tblCheckeDaryafti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldDateSarResid,
--								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')
--					order by tblCheckeDaryafti.fldDateSarResid,tblCheckeDaryafti.fldDateDaryaft

--if @type<>'search' 
--	if @ListGroupAshkhas<>''
--		begin
--		declare @StrDeleteGroupAshkhas varchar(5000)
--		set  @StrDeleteGroupAshkhas='delete from #TempReportCheck 
--			where '+ @ListGroupAshkhas + ''
--			execute(@StrDeleteGroupAshkhas)
--		end
	

if @ListGroupAshkhas <>''
begin
	declare @StrDeleteGroupAshkhas varchar(5000)
	set  @StrDeleteGroupAshkhas='delete from #TempReportCheckPardakht 
		where fldCodeGroupAshkhas NOT IN ('+ @ListGroupAshkhas +')'
		execute(@StrDeleteGroupAshkhas)
end
if @ListCodeAshkhas <>''
begin
	declare @StrDeleteAshkhas varchar(5000)
	set  @StrDeleteAshkhas='delete from #TempReportCheckPardakht 
		where fldCodeSahebeCheck NOT IN ('+ @ListCodeAshkhas +')'
		execute(@StrDeleteAshkhas)
end

if @ListCodeBank <>''
begin

--delete from #TempReportCheckPardakht where fldCodeBank NOT IN @ListCodeBank

	declare @StrDeleteBank varchar(5000)
	set  @StrDeleteBank='delete from #TempReportCheckPardakht 
		where fldCodeBank NOT IN ('+ @ListCodeBank +')'
		execute(@StrDeleteBank)
end
--if @ListCodeVisitor<>''
--	begin
--	if @ListCodeVisitor='-1' --ليست فاکتورهاي بدون ويزيتور
--		begin
--			delete from #TempReportCheck where fldCodeVasete<>''
--		end
--	else
--		begin
--			declare @StrDeleteVisitor varchar(5000)
--			set  @StrDeleteVisitor='delete from #TempReportCheck 
--				where '+ @ListCodeVisitor + ''
--				execute(@StrDeleteVisitor)
--		end
--	end

if @Type<>'search'
	begin
		delete #TempReportCheckPardakht Where fldDateSarResid< @DateSarResidAz
		delete #TempReportCheckPardakht Where fldDateSarResid> @DateSarResidTa
		delete #TempReportCheckPardakht Where fldDatePardakht< @DatePardakhtAz
		delete #TempReportCheckPardakht Where fldDatePardakht> @DatePardakhtTa
		delete #TempReportCheckPardakht Where fldDatePardakht< @DatePassAz
		delete #TempReportCheckPardakht Where fldDatePardakht> @DatePassTa
	end
else if @Type='search'
--begin
--	declare @StrSearch varchar(5000)
--	set  @StrSearch='delete from #TempReportCheckPardakht 
--		where fldShomareCheck <> '+ @ListCodeAshkhas 
--		execute(@StrSearch)
--end
	begin
		--execute('delete #TempReportCheckPardakht Where fldShomareCheck = ' + @fldShomareCheck )


		delete from #TempReportCheckPardakht Where fldShomareCheck <> @fldShomareCheck



	--	execute('delete #TempReportCheckPardakht Where fldShomareCheck not like %' + @ListGroupAshkhas +'%')
	end

--update #TempReportCheckPardakht set fldNameVasete=tblTafzili.fldSharheTafzili from tblTafzili Where #TempReportCheck.fldCodeVasete=tblTafzili.fldCodeTafzili
--update #TempReportCheckPardakht set fldNameBankVagozari =tblKolMoin.fldSharheHesab from tblKolMoin Where tblKolMoin.fldCodeHesab =fldCodeBankVagozari
--update #TempReportCheckPardakht set fldVaziatShow='واگذاري به ' + fldNameBankVagozari where fldVaziat='vagozari'
--update #TempReportCheckPardakht set fldVaziatShow='وصول چک به شماره وصول ' + Convert(varchar,fldShomareVosool) where fldVaziat='vosool'
--update #TempReportCheckPardakht set fldVaziat='foroosh', fldVaziatShow='واگذاري چک به ش پرداخت' + Convert(varchar,fldShomarePardakht) + ' به ' + tbl1.NameShakhs from 
--		(SELECT        tblTafzili.fldSharheTafzili As NameShakhs, tblPardakht.fldShomarePardakht As ShomarePardakht FROM tblTafzili INNER JOIN tblPardakht ON tblTafzili.fldCodeTafzili = tblPardakht.fldCodeTafzili) As Tbl1
--		Where tbl1.ShomarePardakht=fldShomarePardakht

--update TempReportCheckPardakht set fldVaziat ='' where fldVaziat is null
--if @type='vosoolnashode'
--	delete #TempReportCheckPardakht where fldVaziat<>'vosoolnashode'
--if @type='vosool'
--	begin
--		delete #TempReportCheckPardakht where fldVaziat<>'vosool'
--		--update #TempReportCheckPardakht set fldNameHesabeVosool=tblKolMoin.fldSharheHesab from tblKolMoin 
--			--Where #TempReportCheckPardakht.fldCodeHesabeVosool=tblKolMoin.fldCodeHesab
--	end



update #TempReportCheckPardakht set fldNameGroupAshkhas=tblGroupAshkhas.fldGroupName from tblGroupAshkhas Where tblGroupAshkhas.fldGroupId=#TempReportCheckPardakht.fldCodeGroupAshkhas

Set @JameMablagh=(Select Sum(fldMablagh) from #TempReportCheckPardakht)
if @JameMablagh is null
	set @JameMablagh=0

Select ROW_NUMBER() OVER(ORDER BY fldDatePardakht,ID ) AS [Row],ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili
	,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDatePardakht,fldDatePardakhtShow
			,fldShomarePardakht,fldShomarePass,fldDatePass,fldDatePassShow
		 from  #TempReportCheckPardakht

END
GO

-- ===============================================
-- SP: [dbo].[z109ReportCheckPardakhti_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z109ReportCheckPardakhti_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z109ReportCheckPardakhti_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z109ReportCheckPardakhti_WithUserCode]
@Type nvarchar(20),
@fldShomareCheck bigint,
@ListGroupAshkhas varchar(5000)=null,
@ListCodeAshkhas varchar(5000)=null,
@ListCodeBank varchar(5000)=null,
@DateSarResidAz bigint,
@DateSarResidTa bigint,
@DatePardakhtAz bigint,
@DatePardakhtTa bigint,
@DatePassAz bigint,
@DatePassTa bigint,
@userCode bigint,
@JameMablagh bigint output

	
AS
IF 1 = 0 BEGIN
    SET FMTONLY OFF
END
BEGIN
	
SET NOCOUNT ON;


create table #TempReportCheckPardakht(

ID bigint,
fldShomareCheck bigint,
fldShomareHesab bigint,
fldCodeSahebeCheck Nvarchar(10) collate Persian_100_CI_AS,
fldSharheTafzili  Nvarchar(200) collate Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldDateSarResid bigint,
fldDateSarResidShow  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeBank int, 
fldNameBank Nvarchar(100) collate Persian_100_CI_AS, 
fldShobe Nvarchar(40) collate Persian_100_CI_AS,
fldMablagh decimal(18,0),
fldDatePardakht bigint, 
fldDatePardakhtShow Nvarchar(20) collate Persian_100_CI_AS,
fldVaziat  Nvarchar(15) collate Persian_100_CI_AS,
fldShomarePardakht bigint,
fldShomarePass bigint,
fldShomareBazPas bigint,
fldDatePass bigint,
fldDatePassShow nvarchar(15) collate Persian_100_CI_AS,
fldVaziatShow nvarchar(50)  collate Persian_100_CI_AS,
fldNameGroupAshkhas nvarchar(80) collate Persian_100_CI_AS

)

if @type='all' or  @type='search'
	begin

	Insert into  #TempReportCheckPardakht(ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili
	,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDatePardakht,fldDatePardakhtShow
			,fldShomarePardakht,fldShomarePass,fldShomareBazPas,fldDatePass,fldDatePassShow
			 )
		SELECT        dbo.tblCheckePardakhti.ID,dbo.tblCheckePardakhti.fldShomareCheck,dbo.tblCheckePardakhti.fldShomareHesab
		             ,dbo.tblCheckePardakhti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldCodeGroup,tblCheckePardakhti.fldDateSarResid,
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
								 dbo.tblCheckePardakhti.fldCodeBank,dbo.tblKolMoin.fldSharheHesab, dbo.tblCheckePardakhti.fldShobe, 
								 dbo.tblCheckePardakhti.fldMablagh,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,fldShomarePass,dbo.tblCheckePardakhti.fldShomareBazPas,fldDatePass,
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 1, 4) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 5, 2) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 7, 2) AS fldDatePassShow

							
							
                         
		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									 
					order by tblCheckePardakhti.fldDateSarResid,tblCheckePardakhti.fldDatePardakht
	end
	if @type='Pass'
	begin
		Insert into  #TempReportCheckPardakht(ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili
	,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDatePardakht,fldDatePardakhtShow
			,fldShomarePardakht,fldShomarePass,fldShomareBazPas,fldDatePass,fldDatePassShow
			 )
		SELECT        dbo.tblCheckePardakhti.ID,dbo.tblCheckePardakhti.fldShomareCheck,dbo.tblCheckePardakhti.fldShomareHesab
		             ,dbo.tblCheckePardakhti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldCodeGroup,tblCheckePardakhti.fldDateSarResid,
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
								 dbo.tblCheckePardakhti.fldCodeBank,dbo.tblKolMoin.fldSharheHesab, dbo.tblCheckePardakhti.fldShobe, 
								 dbo.tblCheckePardakhti.fldMablagh,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,fldShomarePass,fldShomareBazPas,fldDatePass,
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 1, 4) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 5, 2) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 7, 2) AS fldDatePassShow

							
							
                         
		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 ISNUMERIC(fldShomarePass)=1					 
					order by tblCheckePardakhti.fldDateSarResid,tblCheckePardakhti.fldDatePardakht
	end
if @type='PassNashode'
begin
update tblCheckePardakhti set fldBatel=0 Where  fldBatel is null 

Insert into  #TempReportCheckPardakht(ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili
	,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDatePardakht,fldDatePardakhtShow
			,fldShomarePardakht,fldShomarePass,fldShomareBazPas,fldDatePass,fldDatePassShow
			 )
		SELECT        dbo.tblCheckePardakhti.ID,dbo.tblCheckePardakhti.fldShomareCheck,dbo.tblCheckePardakhti.fldShomareHesab
		             ,dbo.tblCheckePardakhti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldCodeGroup,tblCheckePardakhti.fldDateSarResid,
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
								 dbo.tblCheckePardakhti.fldCodeBank,dbo.tblKolMoin.fldSharheHesab, dbo.tblCheckePardakhti.fldShobe, 
								 dbo.tblCheckePardakhti.fldMablagh,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,fldShomarePass,fldShomareBazPas,fldDatePass,
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 1, 4) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 5, 2) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 7, 2) AS fldDatePassShow           
		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  ISNUMERIC(fldShomarePass)<>1 and isnumeric(fldShomareBazPas)=0 and fldBatel=0 
					order by tblCheckePardakhti.fldDateSarResid,tblCheckePardakhti.fldDatePardakht
	--delete #TempReportCheckPardakht where fldShomarePass=2
	end


if @type='batel'
begin
update tblCheckePardakhti set fldBatel=0 Where  fldBatel is null 

Insert into  #TempReportCheckPardakht(ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili
	,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDatePardakht,fldDatePardakhtShow
			,fldShomarePardakht,fldShomarePass,fldShomareBazPas,fldDatePass,fldDatePassShow
			 )
		SELECT        dbo.tblCheckePardakhti.ID,dbo.tblCheckePardakhti.fldShomareCheck,dbo.tblCheckePardakhti.fldShomareHesab
		             ,dbo.tblCheckePardakhti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldCodeGroup,tblCheckePardakhti.fldDateSarResid,
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
								 dbo.tblCheckePardakhti.fldCodeBank,dbo.tblKolMoin.fldSharheHesab, dbo.tblCheckePardakhti.fldShobe, 
								 dbo.tblCheckePardakhti.fldMablagh,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,fldShomarePass,fldShomareBazPas,fldDatePass,
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 1, 4) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 5, 2) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 7, 2) AS fldDatePassShow           
		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   fldBatel=1 
					order by tblCheckePardakhti.fldDateSarResid,tblCheckePardakhti.fldDatePardakht
	--delete #TempReportCheckPardakht where fldShomarePass=2
	end



if @type='BazPasShode'
begin
Insert into  #TempReportCheckPardakht(ID,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldSharheTafzili
	,fldCodeGroupAshkhas,fldDateSarResid,fldDateSarResidShow,fldCodeBank,fldNameBank, 
			fldShobe,fldMablagh,fldDatePardakht,fldDatePardakhtShow
			,fldShomarePardakht,fldShomarePass,fldShomareBazPas,fldDatePass,fldDatePassShow
			 )
		SELECT        dbo.tblCheckePardakhti.ID,dbo.tblCheckePardakhti.fldShomareCheck,dbo.tblCheckePardakhti.fldShomareHesab
		             ,dbo.tblCheckePardakhti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldCodeGroup,tblCheckePardakhti.fldDateSarResid,
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
								 dbo.tblCheckePardakhti.fldCodeBank,dbo.tblKolMoin.fldSharheHesab, dbo.tblCheckePardakhti.fldShobe, 
								 dbo.tblCheckePardakhti.fldMablagh,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,fldShomarePass,fldShomareBazPas,fldDatePass,
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 1, 4) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 5, 2) + '/' + 
								 SUBSTRING(CONVERT(nvarchar, tblCheckePardakhti.fldDatePass), 7, 2) AS fldDatePassShow

							
							
                         
		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  ISNUMERIC(fldShomareBazPas)=1					 
					order by tblCheckePardakhti.fldDateSarResid,tblCheckePardakhti.fldDatePardakht
	--delete #TempReportCheckPardakht where fldShomarePass=2
	end
--else if @type='vosoolnashode'
--	SELECT        dbo.tblCheckeDaryafti.ID,dbo.tblCheckeDaryafti.fldShomareCheck,dbo.tblCheckeDaryafti.fldShomareHesab,dbo.tblCheckeDaryafti.fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldDateSarResid,
--								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')
--					order by tblCheckeDaryafti.fldDateSarResid,tblCheckeDaryafti.fldDateDaryaft

--if @type<>'search' 
--	if @ListGroupAshkhas<>''
--		begin
--		declare @StrDeleteGroupAshkhas varchar(5000)
--		set  @StrDeleteGroupAshkhas='delete from #TempReportCheck 
--			where '+ @ListGroupAshkhas + ''
--			execute(@StrDeleteGroupAshkhas)
--		end
	

if @ListGroupAshkhas <>''
begin
	declare @StrDeleteGroupAshkhas varchar(5000)
	set  @StrDeleteGroupAshkhas='delete from #TempReportCheckPardakht 
		where fldCodeGroupAshkhas NOT IN ('+ @ListGroupAshkhas +')'
		execute(@StrDeleteGroupAshkhas)
end
if @ListCodeAshkhas <>''
begin
	declare @StrDeleteAshkhas varchar(5000)
	set  @StrDeleteAshkhas='delete from #TempReportCheckPardakht 
		where fldCodeSahebeCheck NOT IN ('+ @ListCodeAshkhas +')'
		execute(@StrDeleteAshkhas)
end

if @ListCodeBank <>''
begin

--delete from #TempReportCheckPardakht where fldCodeBank NOT IN @ListCodeBank

	declare @StrDeleteBank varchar(5000)
	set  @StrDeleteBank='delete from #TempReportCheckPardakht 
		where fldCodeBank NOT IN ('+ @ListCodeBank +')'
		execute(@StrDeleteBank)
end
--if @ListCodeVisitor<>''
--	begin
--	if @ListCodeVisitor='-1' --ليست فاکتورهاي بدون ويزيتور
--		begin
--			delete from #TempReportCheck where fldCodeVasete<>''
--		end
--	else
--		begin
--			declare @StrDeleteVisitor varchar(5000)
--			set  @StrDeleteVisitor='delete from #TempReportCheck 
--				where '+ @ListCodeVisitor + ''
--				execute(@StrDeleteVisitor)
--		end
--	end

if @Type<>'search'
	begin
		delete #TempReportCheckPardakht Where fldDateSarResid< @DateSarResidAz
		delete #TempReportCheckPardakht Where fldDateSarResid> @DateSarResidTa
		delete #TempReportCheckPardakht Where fldDatePardakht< @DatePardakhtAz
		delete #TempReportCheckPardakht Where fldDatePardakht> @DatePardakhtTa
		delete #TempReportCheckPardakht Where fldDatePardakht< @DatePassAz
		delete #TempReportCheckPardakht Where fldDatePardakht> @DatePassTa
	end
else if @Type='search'
--begin
--	declare @StrSearch varchar(5000)
--	set  @StrSearch='delete from #TempReportCheckPardakht 
--		where fldShomareCheck <> '+ @ListCodeAshkhas 
--		execute(@StrSearch)
--end
	begin
		--execute('delete #TempReportCheckPardakht Where fldShomareCheck = ' + @fldShomareCheck )


		delete from #TempReportCheckPardakht Where fldShomareCheck <> @fldShomareCheck



	--	execute('delete #TempReportCheckPardakht Where fldShomareCheck not like %' + @ListGroupAshkhas +'%')
	end

--update #TempReportCheckPardakht set fldNameVasete=tblTafzili.fldSharheTafzili from tblTafzili Where #TempReportCheck.fldCodeVasete=tblTafzili.fldCodeTafzili
--update #TempReportCheckPardakht set fldNameBankVagozari =tblKolMoin.fldSharheHesab from tblKolMoin Where tblKolMoin.fldCodeHesab =fldCodeBankVagozari
--update #TempReportCheckPardakht set fldVaziatShow='واگذاري به ' + fldNameBankVagozari where fldVaziat='vagozari'
--update #TempReportCheckPardakht set fldVaziatShow='وصول چک به شماره وصول ' + Convert(varchar,fldShomareVosool) where fldVaziat='vosool'
--update #TempReportCheckPardakht set fldVaziat='foroosh', fldVaziatShow='واگذاري چک به ش پرداخت' + Convert(varchar,fldShomarePardakht) + ' به ' + tbl1.NameShakhs from 
--		(SELECT        tblTafzili.fldSharheTafzili As NameShakhs, tblPardakht.fldShomarePardakht As ShomarePardakht FROM tblTafzili INNER JOIN tblPardakht ON tblTafzili.fldCodeTafzili = tblPardakht.fldCodeTafzili) As Tbl1
--		Where tbl1.ShomarePardakht=fldShomarePardakht

--update TempReportCheckPardakht set fldVaziat ='' where fldVaziat is null
--if @type='vosoolnashode'
--	delete #TempReportCheckPardakht where fldVaziat<>'vosoolnashode'
--if @type='vosool'
--	begin
--		delete #TempReportCheckPardakht where fldVaziat<>'vosool'
--		--update #TempReportCheckPardakht set fldNameHesabeVosool=tblKolMoin.fldSharheHesab from tblKolMoin 
--			--Where #TempReportCheckPardakht.fldCodeHesabeVosool=tblKolMoin.fldCodeHesab
--	end



update #TempReportCheckPardakht set fldNameGroupAshkhas=tblGroupAshkhas.fldGroupName from tblGroupAshkhas Where tblGroupAshkhas.fldGroupId=#TempReportCheckPardakht.fldCodeGroupAshkhas

Set @JameMablagh=(Select Sum(fldMablagh) from #TempReportCheckPardakht)
if @JameMablagh is null
	set @JameMablagh=0

-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################

Select ROW_NUMBER() OVER(ORDER BY fldDatePardakht,ID ) AS [Row],ID,fldShomareCheck,fldShomareHesab,fldDateSarResidShow,fldCodeBank,fldNameBank,fldCodeSahebeCheck,fldSharheTafzili,fldMablagh,fldDatePardakhtShow,fldShomarePardakht,
fldShobe,fldShomarePass,fldDatePassShow,fldShomareBazPas,fldCodeGroupAshkhas,fldDateSarResid,fldDatePardakht,fldDatePass,ID
		 from  #TempReportCheckPardakht
		 where 
		 -- ##################### Group Ashkhas Limitation
		fldCodeSahebeCheck in (select code from @accessCodes)

END
GO

-- ===============================================
-- SP: [dbo].[z110ShowInfoChecksBargashtShodeInFormBargasht]
-- ===============================================
IF OBJECT_ID(N'dbo.z110ShowInfoChecksBargashtShodeInFormBargasht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z110ShowInfoChecksBargashtShodeInFormBargasht] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z110ShowInfoChecksBargashtShodeInFormBargasht]

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.fldDateBargasht), 1, 4) + '/' 
 + SUBSTRING(CONVERT(nvarchar, 
  dbo.tblCheckeDaryafti.fldDateBargasht), 5, 2) + '/' 
 + SUBSTRING(CONVERT(nvarchar, dbo.tblCheckeDaryafti.fldDateBargasht), 7, 2) 
  AS fldDateBargasht,dbo.tblCheckeDaryafti.fldSharhBargasht,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 
	WHERE  (dbo.tblCheckeDaryafti.fldShomarePardakht IS NULL) AND (dbo.tblCheckeDaryafti.fldVaziat = 'Bargasht')


END
GO

-- ===============================================
-- SP: [dbo].[z111ShowCheckDaryaftiAndVosoolNashodeINfrmBargasht]
-- ===============================================
IF OBJECT_ID(N'dbo.z111ShowCheckDaryaftiAndVosoolNashodeINfrmBargasht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z111ShowCheckDaryaftiAndVosoolNashodeINfrmBargasht] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z111ShowCheckDaryaftiAndVosoolNashodeINfrmBargasht]
	
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)OR
						 (dbo.tblCheckeDaryafti.fldShomarePardakht IS NULL) AND (dbo.tblCheckeDaryafti.fldVaziat='Vagozari')
						 order by tblCheckeDaryafti.fldDateSarResid

						 
END
GO

-- ===============================================
-- SP: [dbo].[z112InsertInfoBargashtCheck]
-- ===============================================
IF OBJECT_ID(N'dbo.z112InsertInfoBargashtCheck', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z112InsertInfoBargashtCheck] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z112InsertInfoBargashtCheck] 
@fldIdCheck bigint,
@fldDateBargasht  int,
@fldSharhBargasht  nvarchar(50),
@Result nvarchar(50) output
    
AS
BEGIN
	
	SET NOCOUNT ON;

   UPDATE [dbo].[tblCheckeDaryafti]
   SET 
		fldDateBargasht=@fldDateBargasht, 
		fldSharhBargasht=@fldSharhBargasht,
		fldVaziat ='Bargasht'       
	WHERE ID=@fldIdCheck 
    set @Result='UpdateOk'
	
END
GO

-- ===============================================
-- SP: [dbo].[z113ReportPorsantTabaghati]
-- ===============================================
IF OBJECT_ID(N'dbo.z113ReportPorsantTabaghati', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z113ReportPorsantTabaghati] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z113ReportPorsantTabaghati]
	@fldCodeVisitor bigint,
	@fldTarikhAz bigint,
	@fldTarikhTa bigint,
	@Type nvarchar(50)
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 #tmpPorsant
		(
			fldCodeVisitor bigint,						
			fldMablaghSumForoosh decimal,
			fldMablaghSumBargashtAzForoosh decimal
		)
if @Type='Foroosh'
		begin
		insert into #tmpPorsant(fldCodeVisitor,fldMablaghSumForoosh,fldMablaghSumBargashtAzForoosh)
		select fldCodeVasete,(fldMablaghKhales) as fldMablaghSumForoosh,(0) as fldMablaghSumBargashtAzForoosh
		from tblRizeForoosh
		where fldCodeVasete=@fldCodeVisitor and fldDate between @fldTarikhAz and @fldTarikhTa
		end
if @Type='BargashtAzForoosh'
		begin
	insert into #tmpPorsant(fldCodeVisitor,fldMablaghSumForoosh,fldMablaghSumBargashtAzForoosh)
		select fldCodeVasete,(0) as fldMablaghSumForoosh,(fldMablaghKhales) as fldMablaghSumBargashtAzForoosh
		from tblRizeBargashtAzForoosh
		where fldCodeVasete=@fldCodeVisitor and fldDate between @fldTarikhAz and @fldTarikhTa
		end


		select ROW_NUMBER()OVER(ORDER BY fldCodeVisitor) as fldRadif,fldCodeVisitor,fldMablaghSumForoosh,fldMablaghSumBargashtAzForoosh from #tmpPorsant 
	
	
END
GO

-- ===============================================
-- SP: [dbo].[z114InsertTarheTakhfifHajmi]
-- ===============================================
IF OBJECT_ID(N'dbo.z114InsertTarheTakhfifHajmi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z114InsertTarheTakhfifHajmi] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z114InsertTarheTakhfifHajmi]

@ID bigint,
@fldCodeKala bigint,
@fldRadif bigint,
@fldTedad int,
@fldDarsad decimal(18,2)

as 

begin

	insert into tblTarheTakhfifHajmi 
		values(@ID,@fldCodeKala,@fldRadif,@fldTedad,@fldDarsad)

end
GO

-- ===============================================
-- SP: [dbo].[z115UpdateTblTarheTakhfifHajmi]
-- ===============================================
IF OBJECT_ID(N'dbo.z115UpdateTblTarheTakhfifHajmi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z115UpdateTblTarheTakhfifHajmi] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z115UpdateTblTarheTakhfifHajmi]

@fldCodeKala bigint,
@fldRadif bigint,
@fldTedad int,
@fldDarsad int,
@flagOut int output
as

begin
	Update tblTarheTakhfifHajmi Set fldTedad =@fldTedad,fldDarsad=@fldDarsad Where fldRadif=@fldRadif and fldCodeKala=@fldCodeKala
	set @flagOut=1
end
GO

-- ===============================================
-- SP: [dbo].[z116TekrariTedadTakhfifKala]
-- ===============================================
IF OBJECT_ID(N'dbo.z116TekrariTedadTakhfifKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z116TekrariTedadTakhfifKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z116TekrariTedadTakhfifKala]

@TedadTakhfif bigint,
@fldCodeKala bigint,
@fldRadif bigint,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountTakhfif int
	if @IDType=0  --براي مقايسه براي حالت اضافه کردن رکورد
		begin
		 set @RowCountTakhfif=(Select Count(fldTedad) from tblTarheTakhfifHajmi  Where fldTedad=@TedadTakhfif and fldCodeKala=@fldCodeKala and  fldRadif<>@fldRadif)
		 set @flagOUt=@RowCountTakhfif
		end
	else
		begin --براي مقايسه با غيرخودش در حالت ويرايش
		   set	@RowCountTakhfif=(Select  Count(fldTedad) from tblTarheTakhfifHajmi  Where fldTedad=@TedadTakhfif and fldCodeKala=@fldCodeKala and fldTedad=@TedadTakhfif and  fldRadif<>@fldRadif)
		   set @flagOUt=@RowCountTakhfif
		end
end
GO

-- ===============================================
-- SP: [dbo].[z117ReportFactorHavaleNashode]
-- ===============================================
IF OBJECT_ID(N'dbo.z117ReportFactorHavaleNashode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z117ReportFactorHavaleNashode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z117ReportFactorHavaleNashode]

AS
IF 1 = 0 BEGIN
 SET FMTONLY OFF
END
BEGIN
	
SET NOCOUNT ON;

create table #TempReportFactor(

ID bigint,
fldShomareFactor bigint,
fldSharheTafzili  Nvarchar(200) collate Persian_100_CI_AS,
fldCodeAshkhas bigint,
fldCodeGroupAshkhas bigint,
fldNameGroup nvarchar(200) collate Persian_100_CI_AS
)
create table #Temp(

fldCount bigint,
fldNameGroup nvarchar(200) collate Persian_100_CI_AS
)

insert into #TempReportFactor(ID,fldShomareFactor,fldSharheTafzili,fldCodeAshkhas,fldCodeGroupAshkhas,fldNameGroup)
select ROW_NUMBER()OVER(ORDER BY dbo.tblRizeForoosh.ID) as Radif,dbo.tblRizeForoosh.fldShomareFactor
,dbo.tblTafzili.fldSharheTafzili,dbo.tblRizeForoosh.fldCodeTafsili,dbo.tblTafzili.fldCodeGroup,dbo.tblGroupAshkhas.fldGroupName from tblRizeForoosh inner join
dbo.tblTafzili on (dbo.tblTafzili.fldCodeTafzili=dbo.tblRizeForoosh.fldCodeTafsili) inner join
dbo.tblGroupAshkhas on (dbo.tblTafzili.fldCodeGroup=dbo.tblGroupAshkhas.fldGroupId)
 where fldShomareFactor NOT in
(select fldShomareFactor from tblHavaleGoroohi)

insert into #Temp(fldCount,fldNameGroup) select  count(fldCodeGroupAshkhas)as fldCount,fldNameGroup  
	from #TempReportFactor group by fldNameGroup
	
	select fldCount,fldNameGroup from #Temp					 
END
GO

-- ===============================================
-- SP: [dbo].[z118VazietTasfieHavale]
-- ===============================================
IF OBJECT_ID(N'dbo.z118VazietTasfieHavale', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z118VazietTasfieHavale] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z118VazietTasfieHavale] 
	@fldShomareHavale bigint
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie4(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheMande][bigint],
	[fldMablagheBargashti][bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,	
	[fldDateSarResid][bigint],
	[fldDateFactor][bigint],
	[ShomareDaryaft][bigint],
	[SharheTafzili][nvarchar](200) COLLATE Persian_100_CI_AS,
	[codeTafzili][nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldCodeGroupAshkhas][bigint],
	[NameGroup][nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldCodeVasete][bigint],
	[NameVasete][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Tell][nvarchar](50) COLLATE Persian_100_CI_AS,
	[Adress][nvarchar](200) COLLATE Persian_100_CI_AS,
	[sumNaghd] bigint,
	[sumBank] bigint,
	[sumCheck] bigint,
	[tedadecheck] int

	)

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

	--جمع مبلغ نقد،جمع مبلغ بانک،جمع مبلغ چک،تعداد چک،تعداد چک،نمایش ریزچکها،نمایش ریز واریزیها
	
	insert into #tmpDaryaftTasfie4
			(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
			Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili, fldMablagheMandeFactor,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
				from  dbo.tblTasfie INNER JOIN
				dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor 
	update #tmpDaryaftTasfie4
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor

 --   update tblRizeTasfie set fldSanad = tblDaryaft.fldShomareSanad from tblDaryaft where tblRizeTasfie.fldShomareDaryaft=tblDaryaft.fldShomareDaryaft

	--select fldsanad from tblRizeTasfie where fldShomareFactor=

	--select * from #tmpDaryaftTasfie4
	--select * from tblRizeTasfie
	
	--بروزرساني جمع مبلغ برگشتی bm
	update #tmpDaryaftTasfie4
	set fldMablagheBargashti=tbl11.fldMablagheBargashti from
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as fldMablagheBargashti from tblRizeTasfie where fldShomareBargashtAzForoosh<>0 group by fldShomareFactor ) as tbl11
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl11.fldShomareFactor

		
	
	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor

	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	update   #tmpDaryaftTasfie4 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti-fldMablagheBargashti

	--بروزرساني کد تفصيلي
	update #tmpDaryaftTasfie4 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl3.fldShomareFactorForoosh

	--بروزرساني نام تفصيلي
	update #tmpDaryaftTasfie4 set SharheTafzili=tbl5.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl5
		where #tmpDaryaftTasfie4.codeTafzili=tbl5.fldCodeTafzili

	--بروزرساني کدگروه 
	update #tmpDaryaftTasfie4 set fldCodeGroupAshkhas=tbl6.fldCodeGroup from
		(Select fldCodeGroup,fldCodeTafzili from tblTafzili) as tbl6
		Where #tmpDaryaftTasfie4.fldCodeTafzili=tbl6.fldCodeTafzili
	
	--بروزرساني نام گروه
	update #tmpDaryaftTasfie4  set NameGroup=tbl6.fldGroupName from
		(Select fldGroupId,fldGroupName from tblGroupAshkhas) as tbl6
		where tbl6.fldGroupId=#tmpDaryaftTasfie4.fldCodeGroupAshkhas
	

	--بروزرساني کد ويزيتورها	
	update #tmpDaryaftTasfie4  set fldCodeVasete = tbl7.fldCodeVasete from
		(SELECT        tblForoosh.fldShomareFactorForoosh, tblRizeForoosh.fldCodeVasete
			FROM            tblForoosh INNER JOIN
							 tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl7
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl7.fldShomareFactorForoosh

	--بروزرساني نام ويزيتورها
	update #tmpDaryaftTasfie4  set NameVasete=tbl8.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl8
		where #tmpDaryaftTasfie4.fldCodeVasete=tbl8.fldCodeTafzili  and fldCodeVasete<>0
	
	update #tmpDaryaftTasfie4 set NameVasete='' where fldCodeVasete=0

	
--select sum(fldMablagh) as sumMablagh,fldShomareDaryaft from tblCheckeDaryafti 
--where fldShomareDaryaft in (select distinct fldShomareDaryaft from tblRizeTasfie ) 
--group by fldShomareDaryaft


--##############################################
--محاسبه جمع چکهای دریافتی برای هر فاکتور
update #tmpDaryaftTasfie4 set sumCheck=tbl4.sumCheclLast from 
(select sum(sumcheck) as sumCheclLast,shomarefactor as shomarefactorlast from 
(select tbl1.sumMablagh as sumCheck,tbl2.fldShomareDaryaft  ,tbl2.fldshomarefactor as shomarefactor from 
(select sum(fldMablagh) as sumMablagh,fldShomareDaryaft from tblCheckeDaryafti  where fldShomareDaryaft<>0  group by fldShomareDaryaft) as tbl1,
(select distinct fldShomareDaryaft ,fldshomarefactor from tblRizeTasfie) as tbl2
where tbl1.fldShomareDaryaft=tbl2.fldShomareDaryaft) as tbl3
group by shomarefactor) as tbl4
where #tmpDaryaftTasfie4.fldShomareFactor=tbl4.shomarefactorlast 


update #tmpDaryaftTasfie4 set sumCheck=0 where sumCheck is NULL
--##############################################


--##############################################
--محاسبه تعداد چکهای دریافتی برای هر فاکتور
update #tmpDaryaftTasfie4 set tedadecheck=tbl4.sumCheclLast from 
(select count(sumcheck) as sumCheclLast,shomarefactor as shomarefactorlast from 
(select tbl1.sumMablagh as sumCheck,tbl2.fldShomareDaryaft  ,tbl2.fldshomarefactor as shomarefactor from 
(select count(fldShomareDaryaft) as sumMablagh,fldShomareDaryaft from  tblCheckeDaryafti where fldShomareDaryaft<>0  group by fldShomareDaryaft) as tbl1,
(select distinct fldShomareDaryaft ,fldshomarefactor from tblRizeTasfie) as tbl2
where tbl1.fldShomareDaryaft=tbl2.fldShomareDaryaft) as tbl3
group by shomarefactor) as tbl4
where #tmpDaryaftTasfie4.fldShomareFactor=tbl4.shomarefactorlast 


update #tmpDaryaftTasfie4 set tedadecheck=0 where tedadecheck is NULL
--##############################################


 execute CodeKolHesab 'bank' ,@codekolbank output
 execute CodeKolHesab 'sandoogh' ,@codekolsandoogh output
--##############################################
--محاسبه جمع واریزی به بانک برای هر فاکتور
update #tmpDaryaftTasfie4 set sumBank= tbl5.sumbed from 
(select sum(fldbedehkar) as SumBed,shomarefactor from 
(select fldSanad,fldcodekol,fldCodeMoin,fldMoinKamel,shomarefactor,fldBedehkar from tblsodooresanad ,
(select tblDaryaft.fldShomareDaryaft, tblDaryaft.fldShomareSanad as sanad,tbl2.fldshomarefactor as shomarefactor from tblDaryaft,
(select distinct fldShomareDaryaft ,fldshomarefactor from tblRizeTasfie  where fldShomareDaryaft<>0) as tbl2
where tblDaryaft.fldShomareDaryaft=tbl2.fldShomareDaryaft) as tbl3
where tblsodooresanad.fldSanad=tbl3.sanad and fldcodekol=@codekolbank) as tbl4
group by shomarefactor) as tbl5
where tbl5.shomarefactor=#tmpDaryaftTasfie4.fldShomareFactor

update #tmpDaryaftTasfie4 set sumBank=0 where sumBank is NULL
--##############################################

--##############################################
--محاسبه جمع واریزی به صندوق برای هر فاکتور
update #tmpDaryaftTasfie4 set sumNaghd= tbl5.sumbed from 
(select sum(fldbedehkar) as SumBed,shomarefactor from 
(select fldSanad,fldcodekol,fldCodeMoin,fldMoinKamel,shomarefactor,fldBedehkar from tblsodooresanad ,
(select tblDaryaft.fldShomareDaryaft, tblDaryaft.fldShomareSanad as sanad,tbl2.fldshomarefactor as shomarefactor from tblDaryaft,
(select distinct fldShomareDaryaft ,fldshomarefactor from tblRizeTasfie  where fldShomareDaryaft<>0) as tbl2
where tblDaryaft.fldShomareDaryaft=tbl2.fldShomareDaryaft) as tbl3
where tblsodooresanad.fldSanad=tbl3.sanad and fldcodekol=@codekolsandoogh) as tbl4
group by shomarefactor) as tbl5
where tbl5.shomarefactor=#tmpDaryaftTasfie4.fldShomareFactor

update #tmpDaryaftTasfie4 set sumNaghd=0 where sumNaghd is NULL
--##############################################


		select NameGroup,fldShomareFactor,fldCodeTafzili,SharheTafzili,fldMablagheMande,SumDaryafti,
		fldMablagheBargashti,fldmandeTasfienashode,sumCheck,tedadecheck,sumBank,sumNaghd,fldDateSarResid,Adress,fldSharh
		 from #tmpDaryaftTasfie4 where fldShomareFactor in(select fldShomareFactor from tblHavaleGoroohi where fldShomareHavale=@fldShomareHavale)

	

END
GO

-- ===============================================
-- SP: [dbo].[z119ReportPorsantVarizVizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.z119ReportPorsantVarizVizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z119ReportPorsantVarizVizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z119ReportPorsantVarizVizitor]
	@fldCodeVisitor bigint,
	@DateAz bigint,
	@DateTa bigint
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;

	declare @strCodeMoinVariz nvarchar(20),@JameVariz bigint
    create table #tmpPorsantVariz
		(
			fldCodeVasete bigint,
			fldNameVizitor nvarchar(200),			
			fldJameVariz bigint
		)
	
		declare @KolBank nvarchar(50),@KolSandoogh nvarchar(50)
		
		execute CodeKolHesab 'bank',@KolBank output
		execute CodeKolHesab 'sandoogh',@KolSandoogh output

		insert into #tmpPorsantVariz
			(fldJameVariz,fldCodeVasete)
		SELECT     SUM(fldBedehkar-fldBestankar) AS Expr1, fldVasete
			FROM         tblSodooreSanad
			WHERE     (fldVasete <> 0) and (fldCodekol=@KolBank or fldCodeKol=@KolSandoogh) and fldDate between   @DateAz and @DateTa
			GROUP BY fldVasete

			
		insert into #tmpPorsantVariz
			(fldJameVariz,fldCodeVasete)
		SELECT     SUM(fldMablagh) AS Expr1,  CONVERT(bigint,fldVasete)AS fldCodeVasete
			FROM         tblCheckeDaryafti
			WHERE     (CONVERT(bigint,fldVasete) <> 0 and ISNUMERIC(fldShomareVosool)=1) and fldDateVosool between   @DateAz and @DateTa
			GROUP BY CONVERT(bigint,fldVasete)

	update #tmpPorsantVariz set fldNameVizitor=tblTafzili.fldSharheTafzili from tblTafzili where #tmpPorsantVariz.fldCodeVasete=tblTafzili.fldCodeTafzili 
	
	select fldCodeVasete,fldNameVizitor,Sum(fldJameVariz) as fldJameVariz from #tmpPorsantVariz where fldCodeVasete=@fldCodeVisitor
		group by fldCodeVasete,fldNameVizitor
	
END
GO

-- ===============================================
-- SP: [dbo].[z120MasterMenu]
-- ===============================================
IF OBJECT_ID(N'dbo.z120MasterMenu', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z120MasterMenu] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z120MasterMenu]
@CodeUser bigint
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, fldNameFarsi, fldNameEnglish
		FROM            tblMenuMaster
		WHERE        (fldNameEnglish NOT IN
									 (SELECT        fldNameEnglish
										FROM            tblMenuSefareshi Where fldCodeUser=@CodeUser))
		order by fldNameFarsi
END
GO

-- ===============================================
-- SP: [dbo].[z121InsertSharhFeeDynamic]
-- ===============================================
IF OBJECT_ID(N'dbo.z121InsertSharhFeeDynamic', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z121InsertSharhFeeDynamic] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z121InsertSharhFeeDynamic]

@Code bigint,
@fldSharh nvarchar(150),
@countRow bigint

as 

begin

	insert into tblSharheFeeDynamic (fldCodeSharh,fldSharh,fldCountRow)
		values(@Code,@fldSharh,@countRow)

end
GO

-- ===============================================
-- SP: [dbo].[z122UpdateSharhFeeDynamic]
-- ===============================================
IF OBJECT_ID(N'dbo.z122UpdateSharhFeeDynamic', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z122UpdateSharhFeeDynamic] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z122UpdateSharhFeeDynamic]

@fldCode int,
@fldSharh nvarchar(150),
@flagOut int output
as

begin
	Update tblSharheFeeDynamic Set fldCodeSharh =@fldCode,fldSharh=@fldSharh Where fldCountRow=@fldCode
	set @flagOut=1
end
GO

-- ===============================================
-- SP: [dbo].[z123TekrariSharheFeeDynamic]
-- ===============================================
IF OBJECT_ID(N'dbo.z123TekrariSharheFeeDynamic', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z123TekrariSharheFeeDynamic] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z123TekrariSharheFeeDynamic]

@fldSharh nvarchar(150),
@Code int,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountTakhfif int
	if @IDType=0  --براي مقايسه براي حالت اضافه کردن رکورد
		begin
		 set @RowCountTakhfif=(Select Count(fldSharh) from tblSharheFeeDynamic  Where fldSharh=@fldSharh)
		 set @flagOUt=@RowCountTakhfif
		end
	else
		begin --براي مقايسه با غيرخودش در حالت ويرايش
		   set	@RowCountTakhfif=(Select  Count(fldSharh) from tblSharheFeeDynamic  Where fldSharh=@fldSharh and fldCountRow<>@Code)
		   set @flagOUt=@RowCountTakhfif
		end
end
GO

-- ===============================================
-- SP: [dbo].[z124InsertMultiFeeDynamic]
-- ===============================================
IF OBJECT_ID(N'dbo.z124InsertMultiFeeDynamic', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z124InsertMultiFeeDynamic] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z124InsertMultiFeeDynamic]

@Id bigint,
@CodeSharh bigint,
@CodeKala bigint,
@fldMablagh decimal,
@countRow bigint

as 

begin



	insert into tblMultiFeeDynamic(id,fldCodeSharh,fldCodeKala,fldFee,fldcountRow)
	values(@Id,@CodeSharh,@CodeKala,@fldMablagh,@countRow)

end
GO

-- ===============================================
-- SP: [dbo].[z125UpdateMultiFeeDynamic]
-- ===============================================
IF OBJECT_ID(N'dbo.z125UpdateMultiFeeDynamic', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z125UpdateMultiFeeDynamic] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z125UpdateMultiFeeDynamic]

@Id bigint,
@CodeSharh bigint,
@CodeKala bigint,
@fldMablagh decimal,
@flagOut int output
as

begin
	Update tblMultiFeeDynamic Set fldCodeSharh=@CodeSharh,fldCodeKala=@CodeKala,fldFee=@fldMablagh Where Id=@Id
	set @flagOut=1
end
GO

-- ===============================================
-- SP: [dbo].[z126TekrariMultiFeeDynamic]
-- ===============================================
IF OBJECT_ID(N'dbo.z126TekrariMultiFeeDynamic', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z126TekrariMultiFeeDynamic] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z126TekrariMultiFeeDynamic]

@fldCodeSharh bigint,
@fldCodeKala bigint,
@fldMablagh decimal,
@Code int,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountTakhfif int
	if @IDType=0  --براي مقايسه براي حالت اضافه کردن رکورد
		begin
		 set @RowCountTakhfif=(Select Count(fldFee) from tblMultiFeeDynamic  Where fldCodeSharh=@fldCodeSharh and fldCodeKala=@fldCodeKala) --and fldFee=@fldMablagh)
		 set @flagOUt=@RowCountTakhfif
		end
	else
		begin --براي مقايسه با غيرخودش در حالت ويرايش
		   set	@RowCountTakhfif=(Select  Count(fldFee) from tblMultiFeeDynamic  Where  fldCodeSharh=@fldCodeSharh and fldCodeKala=@fldCodeKala and fldCountRow<>@Code) --and fldFee=@fldMablagh )
		   set @flagOUt=@RowCountTakhfif
		end
end
--select * from tblMultiFeeDynamic where fldCodeSharh=1001
GO

-- ===============================================
-- SP: [dbo].[z127InsertCheckEbtedaDoreh]
-- ===============================================
IF OBJECT_ID(N'dbo.z127InsertCheckEbtedaDoreh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z127InsertCheckEbtedaDoreh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z127InsertCheckEbtedaDoreh]

@fldCodeSahbeCheck bigint,
@fldShomareCheck nvarchar(30),
@fldShomareHesab bigint,
@fldDateSarResid int,
@fldDateDaryaft int,
@fldCodeBank int,
@fldShobe nvarchar(50),
@fldMablagh decimal,
@strShomareSanad nvarchar output,
@strResult nvarchar(25) output,
@strResult2 nvarchar(25) output
as 

begin
	begin transaction AddRecord
		begin try
		
	declare 
		@intShomareSanad int,
		@strVaziat nvarchar(50),
		@strType nvarchar(50),
		@strRadif1 nvarchar(50),
		@strRadif2 nvarchar(50),
		@count int,
		@fldDate int,
	    @day nvarchar(50),
		@month nvarchar(50),
		@year nvarchar(50),
		@kolVaMoin nvarchar(100),
		@kol nvarchar(50),
		@moin nvarchar(50),
		@Toolkol int,
		@Toolmoin int,
		@KolCheck nvarchar(50),
		@jameMablaghKol decimal
		--execute CodeMoinHesab 'check',@kolVaMoin
		set @kolVaMoin=(Select  fldCodeMoinCheck from tblTanzimat )
		set @Toolkol=(select fldKol from tblPaye)
		set @Toolmoin=(select fldMoin from tblPaye)
		set @kol=(SUBSTRING(@kolVaMoin,1,@Toolkol))
		set @moin=(SUBSTRING(@kolVaMoin,@Toolkol+1,@Toolmoin))
		
		set @KolCheck=(Select  fldKolSarmaye from tblTanzimat )
		
		set @count= (Select COUNT(fldShomareCheck) from tblCheckeDaryafti where fldType='checkebteda')
		set @day=(SUBSTRING(CONVERT(nvarchar, @fldDateDaryaft), 7, 2))
		set @month=(SUBSTRING(CONVERT(nvarchar, @fldDateDaryaft), 5, 2))
		set @year=(SUBSTRING(CONVERT(nvarchar, @fldDateDaryaft), 0, 5))
		set @fldDate=@fldDateDaryaft
		
	
	
 if @count>0
begin

 set @strVaziat='Last'
end
 else
begin

	set @strVaziat='First'
end


if @strVaziat='First'
	begin
	


		set @intShomareSanad=(select MAX(CONVERT(dec, fldSanad)+1)as fldSanad from tblSodooreSanad)
		execute insertSanadFirst @kol,@moin,@kolVaMoin,@fldCodeSahbeCheck,NULL,@fldMablagh,0,'1',@fldDate,NULL,@day,@month,@year,'checkebteda',0,@intShomareSanad output;
			   
		 execute insertSanadLast @KolCheck,NULL,@KolCheck,NULL,'1','0',@fldMablagh,@strRadif1,@fldDate,NULL,@day,@month,@year,'checkebteda',0,@intShomareSanad;
		--execute insertSanadFirst @KolCheck,NULL,@KolCheck,NULL,NULL, @fldMablagh,0,'1',@fldDate,NULL,@day,@month,@year,'ebteda',0,@intShomareSanad;

		insert into tblCheckeDaryafti(fldCodeSahebeCheck,fldShomareCheck,fldShomareHesab,fldDateSarResid,fldDateDaryaft,fldCodeBank,fldShobe,fldMablagh,fldSanad,fldType,fldRadif,fldShomareDaryaft) 	
		values(@fldCodeSahbeCheck,@fldShomareCheck,@fldShomareHesab,@fldDateSarResid,@fldDateDaryaft,@fldCodeBank,@fldShobe,@fldMablagh,@intShomareSanad,'checkebteda','1',0)
	end

if @strVaziat='Last'
	begin
	 	set @intShomareSanad=(select distinct CONVERT(dec, fldSanad) from tblSodooreSanad where fldType='checkebteda')
	    set @strRadif1=(CONVERT(nvarchar, @count+1))
		set @jameMablaghKol=(select sum(fldMablagh)+@fldMablagh from tblCheckeDaryafti where fldType='checkebteda')
		
		delete from tblSodooreSanad Where fldSanad=@intShomareSanad and fldBestankar>0
		execute insertSanadLast @kol,@moin,@kolVaMoin,@fldCodeSahbeCheck,'1',@fldMablagh,'0',@strRadif1,@fldDate,NULL,@day,@month,@year,'checkebteda',0,@intShomareSanad;
	    set @strRadif2=(CONVERT(nvarchar, @count+2))
		execute insertSanadLast @KolCheck,NULL,@KolCheck,NULL,'1','0',@jameMablaghKol,@strRadif2,@fldDate,NULL,@day,@month,@year,'checkebteda',0,@intShomareSanad;
	--execute insertSanadLast '1','1','1',@fldCodeSahbeCheck,'1',@fldMablagh,0,2,971003,NULL,'03','10','97','checkebteda',0,'36';
		
		INSERT INTO tblTest
                         (adad)
VALUES        (1)

		insert into tblCheckeDaryafti(fldCodeSahebeCheck,fldShomareCheck,fldShomareHesab,fldDateSarResid,fldDateDaryaft,fldCodeBank,fldShobe,fldMablagh,fldType,fldSanad,fldRadif,fldShomareDaryaft) 	
		values(@fldCodeSahbeCheck,@fldShomareCheck,@fldShomareHesab,@fldDateSarResid,@fldDateDaryaft,@fldCodeBank,@fldShobe,@fldMablagh,'checkebteda',@intShomareSanad,@strRadif1,0)
	
	end

	update tblSodooreSanad set fldDate= @fldDate,fldDay=@day,fldMonth=@month,fldYear=@year Where fldSanad=@intShomareSanad 	
		
		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

-- ===============================================
-- SP: [dbo].[z127SoodeKala]
-- ===============================================
IF OBJECT_ID(N'dbo.z127SoodeKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z127SoodeKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z127SoodeKala]
	@bigDateMin bigint ,
	@bigDateMax bigint 
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 #tmpGardesheKala
		(
			CodeKala bigint,
			CodeGroup bigint,
			CodeAnbar bigint,
			NameGroup nvarchar(100) collate Persian_100_CI_AS,
			NameKala nvarchar(100) collate Persian_100_CI_AS,
			NameAnbar nvarchar(100) collate Persian_100_CI_AS,
			TedadDarKarton bigint,

			MablagheEbteda bigint,
			TedadeEbteda bigint,
			TedadKartonEbteda nvarchar(100) collate Persian_100_CI_AS,

			MablagheKharid bigint,
			TedadeKharid bigint,
			TedadKartonKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheTolid bigint,
			TedadeTolid bigint,
			TedadKartonTolid nvarchar(100) collate Persian_100_CI_AS,

			TedadMoghayerat bigint,

			MablagheBargashtAzKharid bigint,
			TedadeBargashtAzKharid bigint,
			TedadKartonBargashtAzKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheKhalesKharid bigint,
			TedadeKhalesKharid bigint,
			TedadKartonKhalesKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheKhalesTolid bigint,
			TedadeKhalesTolid bigint,
			TedadKartonKhalesTolid nvarchar(100) collate Persian_100_CI_AS,

			MablagheForoosh bigint,
			TedadeForoosh bigint,
			TedadeKartonForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablagheAvalie bigint,
			TedadeAvalie bigint,
			TedadeKartonAvalie nvarchar(100) collate Persian_100_CI_AS,

			MablagheBargashtAzForoosh bigint,
			TedadeBargashtAzForoosh bigint,
			TedadeKartonBargashtAzForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablagheKhalesForoosh bigint,
			TedadeKhalesForoosh bigint,
			TedadKartonKhalesForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablaghePayan bigint,
			TedadePayan bigint,
			TedadeKartonPayan nvarchar(100) collate Persian_100_CI_AS,

			BahayeTamamShodeForoosh bigint,
			SoodeKala bigint,

			TedadeForoosheJari bigint,
			TedadBargashtAzForoosheJari bigint,
			TedadKhalesForooshejari bigint,
			SoodeJari bigint
		)
		delete from #tmpGardesheKala

		insert into #tmpGardesheKala
			(CodeKala,CodeGroup,NameKala,TedadDarKarton)
			Select  fldCodeKala,fldCodeGroup,fldNameKala,fldTedadJoz 
				from  tblKala

		--update #tmpGardesheKala set TedadeEbteda=Sum(tblRizeKharid.fldTedadeJoz) from tblRizeKharid where #tmpGardesheKala.CodeKala=tblRizeKharid.fldCodeKala group by tblRizeKharid.fldCodeKala

		update           #tmpGardesheKala
			set NameGroup = tblGroupKala.fldGroupName from tblGroupKala Where CodeGroup=tblGroupKala.fldGroupId

		--####تعداد مغایرت####
		update           #tmpGardesheKala
			set TedadMoghayerat=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='Moghayrat' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		update           #tmpGardesheKala
			set TedadMoghayerat-=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeForoosh Where fldType='Moghayrat' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		--####ابتدای دوره####
		update           #tmpGardesheKala
			set tedadeEbteda=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='mojodi_ebteda_doreh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheEbteda=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldFeeKol) as Sum1 from tblRizekharid Where fldType='mojodi_ebteda_doreh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 
			--mojodi_ebteda_doreh



		--کارتن و عدد
		update #tmpGardesheKala Set TedadKartonEbteda=Convert(varchar,floor(tedadeEbteda / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeEbteda, TedadDarKarton) } ) 
			where TedadDarKarton>0
		--######################
		--######خرید#####
		update           #tmpGardesheKala
			set tedadekharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='kharid' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set Mablaghekharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizekharid Where fldType='kharid' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		--کارتن و عدد
		update #tmpGardesheKala Set TedadKartonkharid=Convert(varchar,floor(TedadeKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeKharid, TedadDarKarton) } ) 
			where TedadDarKarton>0
		--#######################


			--######محصول نهایی#####
		update           #tmpGardesheKala
			set tedadetolid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJozNahaei) as Sum1 from tblRizetolid Where fldType='mahsool' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set Mablaghetolid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizetolid Where fldType='mahsool' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		--کارتن و عدد
		update #tmpGardesheKala Set TedadKartontolid=Convert(varchar,floor(Tedadetolid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadetolid, TedadDarKarton) } ) 
			where TedadDarKarton>0
		--#######################

		--######برگشت از خرید#####
		update           #tmpGardesheKala
			set tedadeBargashtAzkharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeBargashtAzkharid Where fldType='bargashtazkharid' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheBargashtAzKharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeBargashtAzkharid Where fldType='bargashtazkharid' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		--کارتن و عدد
		update #tmpGardesheKala Set TedadKartonBargashtAzkharid=Convert(varchar,floor(TedadeBargashtAzKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeBargashtAzKharid, TedadDarKarton) } ) 
			where TedadDarKarton>0
		--#######################

		--######فروش#####
		update           #tmpGardesheKala
			set TedadeForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeForoosh Where fldType='Foroosh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales-fldArzeshAfzode) as Sum1 from tblRizeForoosh Where fldType='Foroosh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		--کارتن و عدد
		update #tmpGardesheKala Set TedadeKartonForoosh=Convert(varchar,floor(TedadeForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeForoosh, TedadDarKarton) } ) 
			where TedadDarKarton>0

		--######مواد اولیه#####
		update           #tmpGardesheKala
			set TedadeAvalie=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJozAvalie) as Sum1 from tblRizeTolid Where fldType='avalie' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheAvalie=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeTolid Where fldType='avalie' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		--کارتن و عدد
		update #tmpGardesheKala Set TedadeKartonAvalie=Convert(varchar,floor(TedadeAvalie / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeAvalie, TedadDarKarton) } ) 
			where TedadDarKarton>0
	--######برگشت از فروش#####
		update           #tmpGardesheKala
			set TedadeBargashtAzForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeBargashtAzForoosh Where fldType='bargashtazforoosh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheBargashtAzForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales - fldArzeshAfzode) as Sum1 from tblRizeBargashtAzForoosh Where fldType='bargashtazforoosh' group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		--کارتن و عدد
		update #tmpGardesheKala Set TedadeKartonForoosh=Convert(varchar,floor(TedadeForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeForoosh, TedadDarKarton) } ) 
			where TedadDarKarton>0
		--#######################
		--#######################
		update           #tmpGardesheKala
			set TedadeEbteda=0 Where TedadeEbteda is null  
		update           #tmpGardesheKala
			set TedadeKharid=0 Where TedadeKharid is null
		update           #tmpGardesheKala
			set Tedadetolid=0 Where Tedadetolid is null
		update           #tmpGardesheKala
			set MablagheTolid=0 Where MablagheTolid is null
		update           #tmpGardesheKala
			set MablagheAvalie=0 Where MablagheAvalie is null
		update           #tmpGardesheKala
			set TedadeAvalie=0 Where TedadeAvalie is null
		update           #tmpGardesheKala
			set TedadeBargashtAzKharid=0 Where TedadeBargashtAzKharid is null
		update           #tmpGardesheKala
			set TedadeForoosh=0 Where TedadeForoosh is null
		update           #tmpGardesheKala
			set TedadeBargashtAzForoosh=0 Where TedadeBargashtAzForoosh is null
		update           #tmpGardesheKala
			set MablagheEbteda=0 Where MablagheEbteda is null
		update           #tmpGardesheKala
			set MablagheKharid=0 Where MablagheKharid is null
		update           #tmpGardesheKala
			set MablagheForoosh=0 Where MablagheForoosh is null
		update           #tmpGardesheKala
			set MablaghePayan=0 Where MablaghePayan is null
		update           #tmpGardesheKala
			set bahayetamamshodeforoosh=0 Where bahayetamamshodeforoosh is null
		update           #tmpGardesheKala
			set SoodeKala=0 Where SoodeKala is null

		update           #tmpGardesheKala
			set TedadMoghayerat=0 Where TedadMoghayerat is null

		--######خالص خرید#######
		update           #tmpGardesheKala 
			set TedadeKhalesKharid=TedadeKharid -TedadeBargashtAzKharid
		update #tmpGardesheKala Set TedadKartonKhalesKharid=Convert(varchar,floor(TedadeKhalesKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalesKharid, TedadDarKarton) } ) 
			where TedadDarKarton>0


		--######خالص تولید#######
		update           #tmpGardesheKala
			set TedadeKhalesTolid=Tedadetolid -Tedadeavalie
		update #tmpGardesheKala Set TedadKartonKhalesTolid=Convert(varchar,floor(TedadeKhalesTolid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalestolid, TedadDarKarton) } ) 
			where TedadDarKarton>0


		update #tmpGardesheKala Set MablagheBargashtAzKharid=0 where MablagheBargashtAzKharid Is NULL
		update #tmpGardesheKala Set MablagheKhalesKharid=MablagheKharid+ MablagheTolid-MablagheBargashtAzKharid-MablagheAvalie

		--######خالص فروش#######
		update           #tmpGardesheKala
			set TedadeKhalesForoosh=TedadeForoosh-TedadeBargashtAzForoosh
		update #tmpGardesheKala Set TedadKartonKhalesForoosh=Convert(varchar,floor(TedadeKhalesForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalesForoosh, TedadDarKarton) } ) 
			where TedadDarKarton>0

		update #tmpGardesheKala Set MablagheKhalesForoosh=MablagheForoosh-MablagheBargashtAzForoosh
		--######پایان دوره#####
		update           #tmpGardesheKala
			set tedadePayan=TedadeEbteda+TedadeKharid+ TedadeTolid+ TedadeBargashtAzForoosh + TedadMoghayerat -TedadeForoosh-TedadeBargashtAzKharid-tedadeavalie
		update #tmpGardesheKala
			set MablaghePayan=(MablagheEbteda+MablagheKharid+Mablaghetolid-mablagheavalie)*tedadePayan/(TedadeEbteda+TedadeKharid+tedadetolid-tedadeavalie) 

			--declare @big1 bigint
			--set @big1= (0+convert(bigint,229413600))*convert(bigint,252)/(0+252) 
			--select @big1

			where (TedadeEbteda+TedadeKharid+tedadetolid-tedadeavalie)<>0
		--کارتن و عدد
		update #tmpGardesheKala Set TedadeKartonPayan=Convert(varchar,floor(TedadePayan/ TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadePayan, TedadDarKarton) } ) 
			where TedadDarKarton>0
		--#######################







		 

		--####انتقال بین انبار و تولید کنترل شود#######

		 declare @TedadForoosheJari bigint,@TedadBargashtAzForoosheJari bigint,@TedadKhalesForooshejari bigint  
		
		update #tmpGardesheKala set MablagheBargashtAzKharid=0 where MablagheBargashtAzKharid is null
		update #tmpGardesheKala set MablagheKhalesKharid= MablagheKharid-MablagheBargashtAzKharid
		update #tmpGardesheKala set BahayeTamamShodeForoosh=MablagheEbteda+MablagheKhalesKharid+Mablaghetolid-MablaghePayan 
		update #tmpGardesheKala set MablagheForoosh=-0 where MablagheForoosh is NULL
		update #tmpGardesheKala set MablagheBargashtAzForoosh=-0 where MablagheBargashtAzForoosh is NULL
		update #tmpGardesheKala set BahayeTamamShodeForoosh=-0 where BahayeTamamShodeForoosh is NULL
		update #tmpGardesheKala set SoodeKala=MablagheForoosh-MablagheBargashtAzForoosh-BahayeTamamShodeForoosh




		--select * from #tmpGardesheKala


		update #tmpGardesheKala set TedadeForoosheJari=tbl1.sumTedad from 
		 (Select sum(fldTedadJoz) as sumTedad,fldCodeKala from tblRizeForoosh where flddate between @bigDateMin and @bigDateMax group by fldCodeKala) as tbl1
		 where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala


		 update #tmpGardesheKala set TedadBargashtAzForoosheJari=tbl1.sumTedad from 
		 (Select sum(fldTedadJoz) as sumTedad,fldCodeKala from tblRizeBargashtAzForoosh where flddate between @bigDateMin and @bigDateMax group by fldCodeKala) as tbl1
		 where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala

		 update #tmpGardesheKala set TedadeForoosheJari=0 where TedadeForoosheJari is null
		 update #tmpGardesheKala set TedadBargashtAzForoosheJari=0 where TedadBargashtAzForoosheJari is null
		 update #tmpGardesheKala set TedadKhalesForooshejari=TedadeForoosheJari-TedadBargashtAzForoosheJari
		 update #tmpGardesheKala set SoodeJari=convert(dec,SoodeKala)*(convert(dec,TedadKhalesForooshejari)/convert(dec,TedadeKhalesForoosh)) where TedadeKhalesForoosh<>0
		 update #tmpGardesheKala set SoodeJari=0 where SoodeJari is NULL
		 --select SoodeJari,SoodeKala,TedadKhalesForooshejari,TedadeKhalesForoosh from #tmpGardesheKala

		 
		 

		Select ROW_NUMBER() OVER(ORDER BY CodeKala ) AS Row, CodeKala,NameGroup,NameKala,TedadDarKarton,TedadeEbteda,TedadKartonEbteda,MablagheEbteda,TedadeKharid,TedadKartonKharid,MablagheKharid, TedadeTolid,MablagheTolid,TedadeAvalie, mablagheavalie , TedadeForoosh,TedadeKartonForoosh,TedadePayan,TedadeKartonPayan,MablaghePayan,BahayeTamamShodeForoosh,MablagheForoosh,MablagheBargashtAzForoosh,(MablagheForoosh-MablagheBargashtAzForoosh) as KhalesForoosh,SoodeKala,
			TedadeKhalesForoosh,TedadeForoosheJari,TedadBargashtAzForoosheJari,TedadKhalesForooshejari,SoodeJari
		from #tmpGardesheKala


	
END
GO

-- ===============================================
-- SP: [dbo].[z127SoodeKalaVizitor]
-- ===============================================
IF OBJECT_ID(N'dbo.z127SoodeKalaVizitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z127SoodeKalaVizitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z127SoodeKalaVizitor]	
	@CodeVizitor bigint,
	@bigDateMin bigint ,
	@bigDateMax bigint ,
	@Type int
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 #tmpGardesheKala
		(
			CodeKala bigint,
			CodeGroup bigint,
			CodeAnbar bigint,
			NameGroup nvarchar(100) collate Persian_100_CI_AS,
			NameKala nvarchar(100) collate Persian_100_CI_AS,
			NameAnbar nvarchar(100) collate Persian_100_CI_AS,
			TedadDarKarton bigint,

			MablagheEbteda bigint,
			TedadeEbteda bigint,
			TedadKartonEbteda nvarchar(100) collate Persian_100_CI_AS,

			MablagheKharid bigint,
			TedadeKharid bigint,
			TedadKartonKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheTolid bigint,
			TedadeTolid bigint,
			TedadKartonTolid nvarchar(100) collate Persian_100_CI_AS,

			TedadMoghayerat bigint,

			MablagheBargashtAzKharid bigint,
			TedadeBargashtAzKharid bigint,
			TedadKartonBargashtAzKharid nvarchar(100) collate Persian_100_CI_AS,

			LastFeeKharid bigint,
			MablagheKhalesKharid bigint,
			TedadeKhalesKharid bigint,
			TedadKartonKhalesKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheKhalesTolid bigint,
			TedadeKhalesTolid bigint,
			TedadKartonKhalesTolid nvarchar(100) collate Persian_100_CI_AS,

			MablagheForoosh bigint,
			TedadeForoosh bigint,
			TedadeKartonForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablagheAvalie bigint,
			TedadeAvalie bigint,
			TedadeKartonAvalie nvarchar(100) collate Persian_100_CI_AS,

			MablagheBargashtAzForoosh bigint,
			TedadeBargashtAzForoosh bigint,
			TedadeKartonBargashtAzForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablagheKhalesForoosh bigint,
			TedadeKhalesForoosh bigint,
			TedadKartonKhalesForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablaghePayan bigint,
			TedadePayan bigint,
			TedadeKartonPayan nvarchar(100) collate Persian_100_CI_AS,

			BahayeTamamShodeForoosh bigint,
			SoodeKala bigint,

			TedadeForoosheJari bigint,
			TedadBargashtAzForoosheJari bigint,
			TedadKhalesForooshejari bigint,
			SoodeJari bigint
		)
		delete from #tmpGardesheKala

		insert into #tmpGardesheKala
			(CodeKala,CodeGroup,NameKala,TedadDarKarton)
			Select  fldCodeKala,fldCodeGroup,fldNameKala,fldTedadJoz 
				from  tblKala

		--update #tmpGardesheKala set TedadeEbteda=Sum(tblRizeKharid.fldTedadeJoz) from tblRizeKharid where #tmpGardesheKala.CodeKala=tblRizeKharid.fldCodeKala group by tblRizeKharid.fldCodeKala
		--if @Type=0 --میانگین
		--	begin			
					update           #tmpGardesheKala
						set NameGroup = tblGroupKala.fldGroupName from tblGroupKala Where CodeGroup=tblGroupKala.fldGroupId

					--####تعداد مغایرت####
					update           #tmpGardesheKala
						set TedadMoghayerat=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='Moghayrat' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

					update           #tmpGardesheKala
						set TedadMoghayerat-=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeForoosh Where fldType='Moghayrat' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

					--####ابتدای دوره####
					update           #tmpGardesheKala
						set tedadeEbteda=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='mojodi_ebteda_doreh' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
					update #tmpGardesheKala 
						set MablagheEbteda=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldFeeKol) as Sum1 from tblRizekharid Where fldType='mojodi_ebteda_doreh' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 
						--mojodi_ebteda_doreh



					--کارتن و عدد
					update #tmpGardesheKala Set TedadKartonEbteda=Convert(varchar,floor(tedadeEbteda / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeEbteda, TedadDarKarton) } ) 
						where TedadDarKarton>0
					--######################
					--######خرید#####
					update           #tmpGardesheKala
						set tedadekharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='kharid' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
					update #tmpGardesheKala 
						set Mablaghekharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizekharid Where fldType='kharid' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

					--کارتن و عدد
					update #tmpGardesheKala Set TedadKartonkharid=Convert(varchar,floor(TedadeKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeKharid, TedadDarKarton) } ) 
						where TedadDarKarton>0
					--#######################
					--######محصول نهایی#####
					update           #tmpGardesheKala
						set tedadetolid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJozNahaei) as Sum1 from tblRizetolid Where fldType='mahsool' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
					update #tmpGardesheKala 
						set Mablaghetolid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizetolid Where fldType='mahsool' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 	

							--کارتن و عدد
					update #tmpGardesheKala Set TedadKartontolid=Convert(varchar,floor(Tedadetolid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadetolid, TedadDarKarton) } ) 
						where TedadDarKarton>0					
					--######برگشت از خرید#####
					update           #tmpGardesheKala
						set tedadeBargashtAzkharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeBargashtAzkharid Where fldType='bargashtazkharid' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
					update #tmpGardesheKala 
						set MablagheBargashtAzKharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeBargashtAzkharid Where fldType='bargashtazkharid' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

					--کارتن و عدد
					update #tmpGardesheKala Set TedadKartonBargashtAzkharid=Convert(varchar,floor(TedadeBargashtAzKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeBargashtAzKharid, TedadDarKarton) } ) 
						where TedadDarKarton>0
					--#######################

					--######فروش#####
					update           #tmpGardesheKala
						set TedadeForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeForoosh Where fldType='Foroosh' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
					update #tmpGardesheKala 
						set MablagheForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales-fldArzeshAfzode) as Sum1 from tblRizeForoosh Where fldType='Foroosh' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

					--کارتن و عدد
					update #tmpGardesheKala Set TedadeKartonForoosh=Convert(varchar,floor(TedadeForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeForoosh, TedadDarKarton) } ) 
						where TedadDarKarton>0
					--######مواد اولیه#####
					update           #tmpGardesheKala
						set TedadeAvalie=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJozAvalie) as Sum1 from tblRizeTolid Where fldType='avalie' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
					update #tmpGardesheKala 
						set MablagheAvalie=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeTolid Where fldType='avalie' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

					--کارتن و عدد
					update #tmpGardesheKala Set TedadeKartonAvalie=Convert(varchar,floor(TedadeAvalie / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeAvalie, TedadDarKarton) } ) 
						where TedadDarKarton>0
				--######برگشت از فروش#####
					update           #tmpGardesheKala
						set TedadeBargashtAzForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeBargashtAzForoosh Where fldType='bargashtazforoosh' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
					update #tmpGardesheKala 
						set MablagheBargashtAzForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales-fldArzeshAfzode) as Sum1 from tblRizeBargashtAzForoosh Where fldType='bargashtazforoosh' group by fldCodeKala) as tbl1
						Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

					--کارتن و عدد
					update #tmpGardesheKala Set TedadeKartonForoosh=Convert(varchar,floor(TedadeForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeForoosh, TedadDarKarton) } ) 
						where TedadDarKarton>0
					--#######################
					--#######################
					update           #tmpGardesheKala
						set TedadeEbteda=0 Where TedadeEbteda is null  
					update           #tmpGardesheKala
						set TedadeKharid=0 Where TedadeKharid is null
					update           #tmpGardesheKala
						set Tedadetolid=0 Where Tedadetolid is null
					update           #tmpGardesheKala
						set MablagheTolid=0 Where MablagheTolid is null
					update           #tmpGardesheKala
						set MablagheAvalie=0 Where MablagheAvalie is null
					update           #tmpGardesheKala
						set TedadeAvalie=0 Where TedadeAvalie is null
					update           #tmpGardesheKala
						set TedadeBargashtAzKharid=0 Where TedadeBargashtAzKharid is null
					update           #tmpGardesheKala
						set TedadeForoosh=0 Where TedadeForoosh is null
					update           #tmpGardesheKala
						set TedadeBargashtAzForoosh=0 Where TedadeBargashtAzForoosh is null
					update           #tmpGardesheKala
						set MablagheEbteda=0 Where MablagheEbteda is null
					update           #tmpGardesheKala
						set MablagheKharid=0 Where MablagheKharid is null
					update           #tmpGardesheKala
						set MablagheForoosh=0 Where MablagheForoosh is null
					update           #tmpGardesheKala
						set MablaghePayan=0 Where MablaghePayan is null
					update           #tmpGardesheKala
						set bahayetamamshodeforoosh=0 Where bahayetamamshodeforoosh is null
					update           #tmpGardesheKala
						set SoodeKala=0 Where SoodeKala is null

					update           #tmpGardesheKala
						set TedadMoghayerat=0 Where TedadMoghayerat is null

					--######خالص خرید#######
					update           #tmpGardesheKala
						set TedadeKhalesKharid=TedadeKharid -TedadeBargashtAzKharid
					update #tmpGardesheKala Set TedadKartonKhalesKharid=Convert(varchar,floor(TedadeKhalesKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalesKharid, TedadDarKarton) } ) 
						where TedadDarKarton>0

					update #tmpGardesheKala Set MablagheKhalesKharid=MablagheKharid-MablagheBargashtAzKharid

				--######خالص تولید#######
					update           #tmpGardesheKala
						set TedadeKhalesTolid=Tedadetolid -Tedadeavalie
					update #tmpGardesheKala Set TedadKartonKhalesTolid=Convert(varchar,floor(TedadeKhalesTolid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalestolid, TedadDarKarton) } ) 
						where TedadDarKarton>0


					update #tmpGardesheKala Set MablagheBargashtAzKharid=0 where MablagheBargashtAzKharid Is NULL
					update #tmpGardesheKala Set MablagheKhalesKharid=MablagheKharid+ MablagheTolid-MablagheBargashtAzKharid-MablagheAvalie
					--######خالص فروش#######
					update           #tmpGardesheKala
						set TedadeKhalesForoosh=TedadeForoosh-TedadeBargashtAzForoosh
					update #tmpGardesheKala Set TedadKartonKhalesForoosh=Convert(varchar,floor(TedadeKhalesForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalesForoosh, TedadDarKarton) } ) 
						where TedadDarKarton>0

					update #tmpGardesheKala set MablagheBargashtAzForoosh=0 where MablagheBargashtAzForoosh is NULl
					update #tmpGardesheKala Set MablagheKhalesForoosh=MablagheForoosh-MablagheBargashtAzForoosh
					--######پایان دوره#####
					update           #tmpGardesheKala
						set tedadePayan=TedadeEbteda+TedadeKharid+ TedadeTolid+ TedadeBargashtAzForoosh + TedadMoghayerat -TedadeForoosh-TedadeBargashtAzKharid-tedadeavalie
					update #tmpGardesheKala
						set MablaghePayan=(MablagheEbteda+MablagheKharid+Mablaghetolid-mablagheavalie)*tedadePayan/(TedadeEbteda+TedadeKharid+tedadetolid-tedadeavalie) 

						--declare @big1 bigint
						--set @big1= (0+convert(bigint,229413600))*convert(bigint,252)/(0+252) 
						--select @big1

						where (TedadeEbteda+TedadeKharid+tedadetolid-tedadeavalie)<>0
					--کارتن و عدد
					update #tmpGardesheKala Set TedadeKartonPayan=Convert(varchar,floor(TedadePayan/ TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadePayan, TedadDarKarton) } ) 
						where TedadDarKarton>0
					--#######################







		 

					--####انتقال بین انبار و تولید کنترل شود#######

					 declare @TedadForoosheJari bigint,@TedadBargashtAzForoosheJari bigint,@TedadKhalesForooshejari bigint  
		
					update #tmpGardesheKala set MablagheKhalesKharid=0 where MablagheKhalesKharid is NULL
					update #tmpGardesheKala set Mablaghetolid=0 where Mablaghetolid is NULL
					update #tmpGardesheKala set MablaghePayan=0 where MablaghePayan is NULL

					update #tmpGardesheKala set BahayeTamamShodeForoosh=MablagheEbteda +MablagheKhalesKharid+Mablaghetolid-MablaghePayan
					update #tmpGardesheKala set BahayeTamamShodeForoosh=-0 where BahayeTamamShodeForoosh is NULL
					update #tmpGardesheKala set SoodeKala=MablagheKhalesForoosh-BahayeTamamShodeForoosh
			--end



		--select * from #tmpGardesheKala

			

		update #tmpGardesheKala set TedadeForoosheJari=tbl1.sumTedad from 
		 (Select sum(fldTedadJoz) as sumTedad,fldCodeKala from tblRizeForoosh where fldCodeVasete=@CodeVizitor and flddate between @bigDateMin and @bigDateMax group by fldCodeKala) as tbl1
		 where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala


		 update #tmpGardesheKala set TedadBargashtAzForoosheJari=tbl1.sumTedad from 
		 (Select sum(fldTedadJoz) as sumTedad,fldCodeKala from tblRizeBargashtAzForoosh where fldCodeVasete=@CodeVizitor and flddate between @bigDateMin and @bigDateMax group by fldCodeKala) as tbl1
		 where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala

		 update #tmpGardesheKala set TedadeForoosheJari=0 where TedadeForoosheJari is null
		 update #tmpGardesheKala set TedadBargashtAzForoosheJari=0 where TedadBargashtAzForoosheJari is null
		 update #tmpGardesheKala set TedadKhalesForooshejari=TedadeForoosheJari-TedadBargashtAzForoosheJari

		 update #tmpGardesheKala set TedadKhalesForooshejari=0 where TedadKhalesForooshejari is null
		 update #tmpGardesheKala set SoodeJari=convert(dec,SoodeKala)*(convert(dec,TedadKhalesForooshejari)/convert(dec,TedadeKhalesForoosh)) where TedadeKhalesForoosh<>0


		if @Type=1 --آخرین فی خرید
			begin	
				update #tmpGardesheKala set	LastFeeKharid=0
				update #tmpGardesheKala set MablagheKhalesKharid =0

				update #tmpGardesheKala set LastFeeKharid=tbl5.fldfeejoz from
					(select fldfeejoz,fldCodeKala from
						(SELECT         fldCodeKala,row_number() over (partition by fldCodeKala order by flddate desc) RowNo,fldfeejoz
						FROM            [tblRizeKharid]  where fldtype<>'enteghal') DB_Address
						where RowNo=1) as tbl5 
						where #tmpGardesheKala.CodeKala=tbl5.fldCodeKala

				update #tmpGardesheKala set MablagheKhalesKharid=LastFeeKharid*#tmpGardesheKala.TedadKhalesForooshejari

				--update #tmpGardesheKala set MablagheForoosh

				update #tmpGardesheKala set MablagheForoosh=0
				update #tmpGardesheKala set MablagheForoosh=tbl1.sumTedad from 
					 (Select sum(fldMablaghKhales) as sumTedad,fldCodeKala from tblRizeForoosh where fldCodeVasete=@CodeVizitor and flddate between @bigDateMin and @bigDateMax group by fldCodeKala) as tbl1
					 where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala

				update #tmpGardesheKala set MablagheForoosh=MablagheForoosh-tbl1.sumTedad from 
					 (Select sum(fldMablaghKhales) as sumTedad,fldCodeKala from tblRizeBargashtAzForoosh where fldCodeVasete=@CodeVizitor and flddate between @bigDateMin and @bigDateMax group by fldCodeKala) as tbl1
					 where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala

				update #tmpGardesheKala set MablagheForoosh=0 where MablagheForoosh is null
				update #tmpGardesheKala set MablagheKhalesKharid=0 where MablagheKhalesKharid is null

				update #tmpGardesheKala set SoodeJari=MablagheForoosh-MablagheKhalesKharid
				update #tmpGardesheKala set SoodeJari=0 where SoodeJari is null
			end
		 
		 --select * from tblRizeKharid where fldCodeKala=10703

		Select ROW_NUMBER() OVER(ORDER BY CodeKala ) AS Row, CodeKala,NameGroup,NameKala,TedadDarKarton,TedadeEbteda,TedadKartonEbteda,MablagheEbteda,TedadeKharid,TedadKartonKharid,MablagheKharid, TedadeTolid,MablagheTolid,TedadeAvalie, mablagheavalie,TedadeForoosh,TedadeKartonForoosh,TedadePayan,TedadeKartonPayan,MablaghePayan,BahayeTamamShodeForoosh,MablagheForoosh,MablagheBargashtAzForoosh,MablagheKhalesForoosh,SoodeKala,
			LastFeeKharid,MablagheKhalesKharid ,TedadeKhalesForoosh,TedadeForoosheJari,TedadBargashtAzForoosheJari,TedadKhalesForooshejari,SoodeJari  
		from #tmpGardesheKala


	
END
GO

-- ===============================================
-- SP: [dbo].[z128ShowCheakEbtedaDoreh]
-- ===============================================
IF OBJECT_ID(N'dbo.z128ShowCheakEbtedaDoreh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z128ShowCheakEbtedaDoreh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[z128ShowCheakEbtedaDoreh]

as
begin
	select dbo.tblCheckeDaryafti.ID,fldSanad,fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldShomareCheck,dbo.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
			,dbo.tblBankeMoshtari.fldNameBank,fldCodeBank,tblCheckeDaryafti.fldShobe,fldMablagh from tblCheckeDaryafti inner join 
			 dbo.tblBankeMoshtari ON dbo.tblCheckeDaryafti.fldCodeBank = dbo.tblBankeMoshtari.ID inner join
			 dbo.tblTafzili on dbo.tblCheckeDaryafti.fldCodeSahebeCheck=dbo.tblTafzili.fldCodeTafzili
			 where fldType='checkebteda'
end
GO

-- ===============================================
-- SP: [dbo].[z129DeleteCheakEbtedaDoreh]
-- ===============================================
IF OBJECT_ID(N'dbo.z129DeleteCheakEbtedaDoreh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z129DeleteCheakEbtedaDoreh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[z129DeleteCheakEbtedaDoreh]
@id bigint

as
begin
	begin transaction AddRecord
		begin try

	declare @strRadif nvarchar(50),
			@jamMablagh decimal,
			@strResult nvarchar(50),
			@strResult2 nvarchar(50),
			@intShomareSanad int,
			@count int

	set @strRadif=(select fldRadif from tblCheckeDaryafti where id=@id)
	set @intShomareSanad=(select fldSanad from tblCheckeDaryafti where id=@id)


	delete from tblSodooreSanad where fldType='checkebteda' and fldRadif=@strRadif

	--delete from tblSodooreSanad Where fldSanad=@intShomareSanad and fldBestankar>0
	delete from tblCheckeDaryafti
			 where id=@id
	set @count=(Select COUNT(fldShomareCheck) from tblCheckeDaryafti where fldType='checkebteda')
	if @count>0
	begin
	set @jamMablagh=(select sum(fldMablagh) from tblCheckeDaryafti where fldType='checkebteda')
	update tblSodooreSanad set fldBestankar=@jamMablagh , fldRadif=@strRadif Where fldSanad=@intShomareSanad and fldBestankar>0
	end
	else
	begin
	delete from tblSodooreSanad Where fldSanad=@intShomareSanad and fldBestankar>0
	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

-- ===============================================
-- SP: [dbo].[z130UpdateCheakEbtedaDoreh]
-- ===============================================
IF OBJECT_ID(N'dbo.z130UpdateCheakEbtedaDoreh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z130UpdateCheakEbtedaDoreh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[z130UpdateCheakEbtedaDoreh]
@id bigint,
@fldCodeSahbeCheck bigint,
@fldShomareCheck nvarchar(30),
@fldShomareHesab bigint,
@fldDateSarResid int,
@fldDateDaryaft int,
@fldCodeBank int,
@fldShobe nvarchar(50),
@fldMablagh decimal,
@strResult nvarchar(25) output

as
begin
begin transaction AddRecord
begin try
	declare @day nvarchar(10),@month nvarchar(10),@year nvarchar(10),@fldDate nvarchar(10)
	declare @strRadif nvarchar(50),
			@jamMablagh decimal,
			@strResult2 nvarchar(50),
			@intShomareSanad int,
			@count int

				set @strRadif=(select fldRadif from tblCheckeDaryafti where ID=@id)
	set @intShomareSanad=(select fldSanad from tblCheckeDaryafti where ID=@id)
			
			update tblCheckeDaryafti 
			set	
				fldCodeSahebeCheck=@fldCodeSahbeCheck,
				fldShomareCheck =@fldShomareCheck,
				fldShomareHesab =@fldShomareHesab,
				fldDateSarResid =@fldDateSarResid,
				fldDateDaryaft =@fldDateDaryaft,
				fldCodeBank =@fldCodeBank,
				fldShobe =@fldShobe,
				fldMablagh =@fldMablagh,
				fldShomareDaryaft=0
			where ID =@id 

			set @day=(SUBSTRING(CONVERT(nvarchar, @fldDateDaryaft), 7, 2))
			set @month=(SUBSTRING(CONVERT(nvarchar, @fldDateDaryaft), 5, 2))
			set @year=(SUBSTRING(CONVERT(nvarchar, @fldDateDaryaft), 0, 5))
			set @fldDate= @fldDateDaryaft --(CONVERT(int, @year+@month+@day))

			set @jamMablagh=(select sum(fldMablagh) from tblCheckeDaryafti where fldType='checkebteda')
			update tblSodooreSanad set fldBestankar=@jamMablagh , fldRadif=@strRadif,fldDate= @fldDate,fldDay=@day,fldMonth=@month,fldYear=@year Where fldSanad=@intShomareSanad and fldBestankar>0 

		
				
			update tblSodooreSanad set fldCodeTafzili=@fldCodeSahbeCheck, fldBedehkar=@fldMablagh ,fldDate= @fldDate,fldDay=@day,fldMonth=@month,fldYear=@year Where fldSanad=@intShomareSanad and fldRadif=@strRadif and fldBedehkar>0

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

-- ===============================================
-- SP: [dbo].[z140MojoodieKalaBatchnumber]
-- ===============================================
IF OBJECT_ID(N'dbo.z140MojoodieKalaBatchnumber', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z140MojoodieKalaBatchnumber] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z140MojoodieKalaBatchnumber]

@CodeKala bigint
as 
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	Create Table #tmpMovaghat(
		batchNumber nvarchar(20) COLLATE Persian_100_CI_AS,
		TedadeJoz bigint,
		TedadKol nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed1 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldTedadDarKarton bigint
	)

	Create Table #tmpShow(
		batchNumber nvarchar(20) COLLATE Persian_100_CI_AS,
		SumTedad bigint,
		TedadKol nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed1 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldTedadDarKarton bigint,
		fldTedadVoroodKartonShow Nvarchar(100) COLLATE Persian_100_CI_AS
	)

	delete #tmpShow
	delete #tmpMovaghat

	insert into #tmpMovaghat
		(batchNumber,TedadeJoz)
	Select fldbatchNumber,fldTedadJoz  from tblRizeKharid Where fldCodeKala=@CodeKala

		insert into #tmpMovaghat
		(batchNumber,TedadeJoz)
	Select fldbatchNumber,fldTedadJoz  from tblRizeBargashtAzForoosh Where fldCodeKala=@CodeKala

	insert into #tmpMovaghat
		(batchNumber,TedadeJoz)
	Select fldbatchNumber,-1*fldTedadJoz  from tblRizeForoosh Where fldCodeKala=@CodeKala

	insert into #tmpMovaghat
		(batchNumber,TedadeJoz)
	Select fldbatchNumber,-1*fldTedadJozAvalie  from tblRizeTolid Where fldCodeKala=@CodeKala And fldType='avalie'

	insert into #tmpMovaghat
		(batchNumber,TedadeJoz)
	Select fldbatchNumber,fldTedadJozNahaei  from tblRizetolid Where fldCodeKala=@CodeKala And fldType='mahsool'

	insert into #tmpMovaghat
		(batchNumber,TedadeJoz)
	Select fldbatchNumber,-1*fldTedadJoz  from tblRizeBargashtAzKharid Where fldCodeKala=@CodeKala

	update #tmpMovaghat set batchNumber=0 Where batchNumber Is Null
	
	--update #tmpMovaghat set batchNumber= substring(convert(nvarchar(10),DateEngheza),0,5) +'/' +substring(convert(nvarchar(10),DateEngheza),5,2) + '/' + substring(convert(nvarchar(10),DateEngheza),7,2) where DateEngheza<>'0'
	
	update #tmpMovaghat set fldNameVahed1=tbl1.fldNameVahed from
		(Select fldNameVahed,fldCodeKala from tblVahed,tblKala Where tblVahed.ID=tblKala.fldCodeVahed1 and fldCodeKala=@CodeKala) as tbl1 where 1=1

	
	update #tmpMovaghat set fldNameVahed2=tbl1.fldNameVahed from
		(Select fldNameVahed,fldCodeKala from tblVahed,tblKala Where tblVahed.ID=tblKala.fldCodeVahed2 and fldCodeKala=@CodeKala) as tbl1 where 1=1



	Insert into #tmpShow (batchNumber,SumTedad,fldNameVahed1,fldNameVahed2,fldTedadDarKarton)
		Select   batchNumber ,Sum(TedadeJoz) As SumTedad,fldNameVahed1,fldNameVahed2,fldTedadDarKarton  from #tmpMovaghat group by batchNumber,fldNameVahed1,fldNameVahed2,fldTedadDarKarton

	declare @TedadDarKarton bigint
	set @TedadDarKarton=(select fldTedadJoz from tblKala where fldCodeKala=@CodeKala)

	
	if @TedadDarKarton>0 
		update #tmpShow Set TedadKol=Convert(varchar,floor(SumTedad / @TedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(SumTedad, @TedadDarKarton) } ) + ' ' + fldNameVahed1			
	else
		update #tmpShow Set TedadKol=''

	Select batchNumber ,SumTedad ,TedadKol,fldNameVahed1,fldNameVahed2 from #tmpShow
	
end
GO

-- ===============================================
-- SP: [dbo].[z140MojoodieKalaDateEngheza]
-- ===============================================
IF OBJECT_ID(N'dbo.z140MojoodieKalaDateEngheza', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z140MojoodieKalaDateEngheza] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z140MojoodieKalaDateEngheza]

@CodeKala bigint
as 
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	Create Table #tmpMovaghat(
		DateEngheza nvarchar(20) COLLATE Persian_100_CI_AS,
		DateSakht nvarchar(20) COLLATE Persian_100_CI_AS,
		BatchNumber nvarchar(20) COLLATE Persian_100_CI_AS,
		GheimateMasrafkonande decimal(18,0),
		TedadeJoz bigint,
		TedadKol nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed1 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldTedadDarKarton bigint
	)

	Create Table #tmpShow(
		DateEngheza nvarchar(20) COLLATE Persian_100_CI_AS,
		DateSakht nvarchar(20) COLLATE Persian_100_CI_AS,
		BatchNumber nvarchar(20) COLLATE Persian_100_CI_AS,
		GheimateMasrafkonande decimal(18,0),
		SumTedad bigint,
		TedadKol nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed1 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldTedadDarKarton bigint,
		fldTedadVoroodKartonShow Nvarchar(100) COLLATE Persian_100_CI_AS
	)

	delete #tmpShow
	delete #tmpMovaghat

	insert into #tmpMovaghat
		(DateEngheza,DateSakht,BatchNumber,GheimateMasrafkonande,TedadeJoz)
	Select fldDateEngheza,fldDateSakht,fldBatchNumber,fldGhymatMasrafkonande,fldTedadJoz  from tblRizeKharid Where fldCodeKala=@CodeKala

		insert into #tmpMovaghat
		(DateEngheza,DateSakht,BatchNumber,GheimateMasrafkonande,TedadeJoz)
	Select fldDateEngheza,fldDateSakht,fldBatchNumber,fldGhymatMasrafkonande,fldTedadJoz  from tblRizeBargashtAzForoosh Where fldCodeKala=@CodeKala

	insert into #tmpMovaghat
		(DateEngheza,DateSakht,BatchNumber,GheimateMasrafkonande,TedadeJoz)
	Select fldDateEngheza,fldDateSakht,fldBatchNumber,fldGhymatMasrafkonande,-1*fldTedadJoz  from tblRizeForoosh Where fldCodeKala=@CodeKala

	insert into #tmpMovaghat
		(DateEngheza,DateSakht,BatchNumber,GheimateMasrafkonande,TedadeJoz)
	Select fldDateEngheza,fldDateSakht,fldBatchNumber,fldGhymatMasrafkonande,-1*fldTedadJozAvalie  from tblRizeTolid Where fldCodeKala=@CodeKala And fldType='avalie'

	insert into #tmpMovaghat
		(DateEngheza,DateSakht,BatchNumber,GheimateMasrafkonande,TedadeJoz)
	Select fldDateEngheza,fldDateSakht,fldBatchNumber,fldGhymatMasrafkonande,fldTedadJozNahaei  from tblRizetolid Where fldCodeKala=@CodeKala And fldType='mahsool'

	insert into #tmpMovaghat
		(DateEngheza,DateSakht,BatchNumber,GheimateMasrafkonande,TedadeJoz)
	Select fldDateEngheza,fldDateSakht,fldBatchNumber,fldGhymatMasrafkonande,-1*fldTedadJoz  from tblRizeBargashtAzKharid Where fldCodeKala=@CodeKala

	update #tmpMovaghat set DateEngheza=0 Where DateEngheza Is Null	
	update #tmpMovaghat set DateEngheza= substring(convert(nvarchar(10),DateEngheza),0,5) +'/' +substring(convert(nvarchar(10),DateEngheza),5,2) + '/' + substring(convert(nvarchar(10),DateEngheza),7,2) where DateEngheza<>'0'	

	update #tmpMovaghat set DateSakht=0 Where DateSakht Is Null	
	update #tmpMovaghat set DateSakht= substring(convert(nvarchar(10),DateSakht),0,5) +'/' +substring(convert(nvarchar(10),DateSakht),5,2) + '/' + substring(convert(nvarchar(10),DateSakht),7,2) where DateSakht<>'0'	

	update #tmpMovaghat set BatchNumber=0 Where BatchNumber Is Null		

	update #tmpMovaghat set GheimateMasrafkonande=0 Where GheimateMasrafkonande Is Null	
	

	update #tmpMovaghat set fldNameVahed1=tbl1.fldNameVahed from
		(Select fldNameVahed,fldCodeKala from tblVahed,tblKala Where tblVahed.ID=tblKala.fldCodeVahed1 and fldCodeKala=@CodeKala) as tbl1 where 1=1

	
	update #tmpMovaghat set fldNameVahed2=tbl1.fldNameVahed from
		(Select fldNameVahed,fldCodeKala from tblVahed,tblKala Where tblVahed.ID=tblKala.fldCodeVahed2 and fldCodeKala=@CodeKala) as tbl1 where 1=1



	Insert into #tmpShow (DateEngheza,DateSakht,BatchNumber,GheimateMasrafkonande,SumTedad,fldNameVahed1,fldNameVahed2,fldTedadDarKarton)
		Select   DateEngheza,DateSakht,BatchNumber,GheimateMasrafkonande ,Sum(TedadeJoz) As SumTedad,fldNameVahed1,fldNameVahed2,fldTedadDarKarton  from #tmpMovaghat group by DateEngheza,DateSakht,BatchNumber,GheimateMasrafkonande,fldNameVahed1,fldNameVahed2,fldTedadDarKarton

	declare @TedadDarKarton bigint
	set @TedadDarKarton=(select fldTedadJoz from tblKala where fldCodeKala=@CodeKala)

	
	if @TedadDarKarton>0 
		update #tmpShow Set TedadKol=Convert(varchar,floor(SumTedad / @TedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(SumTedad, @TedadDarKarton) } ) + ' ' + fldNameVahed1			
	else
		update #tmpShow Set TedadKol=''

	Select DateEngheza,DateSakht,BatchNumber,GheimateMasrafkonande ,SumTedad ,TedadKol,fldNameVahed1,fldNameVahed2 from #tmpShow
	
end
GO

-- ===============================================
-- SP: [dbo].[z141InsertMoghyratAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.z141InsertMoghyratAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z141InsertMoghyratAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z141InsertMoghyratAnbar]
@strResult nvarchar(25) output,
@strResult2 nvarchar(25) output,
@fldCodeKala bigint,
@fldCodeAnbar bigint,
@fldShomareJoz decimal(18,2),
@fldShomareshJozNahei decimal(18,2),
@fldCountShomaresh decimal(18,2),
@fldDate bigint,
@fldTime nvarchar(20),
@tedad decimal(18,2)


as 
begin
	declare @Radif bigint
	declare @MaboTafavotTedad decimal(18,2)
begin transaction AddRecord
		begin try
	
			if @fldShomareshJozNahei=0
	begin
	if @fldCountShomaresh=1
	
	insert into tblMoghayratMojoodieAnbar(fldCodeKala,fldCodeAnbar,fldShomarsheJoz1,fldShomarsheJoz2,fldShomarsheJoz3,fldShomarsheJozNehai)				
		values(@fldCodeKala,@fldCodeAnbar,@fldShomareJoz,null,null,null)
	
	else if @fldCountShomaresh=2
		update tblMoghayratMojoodieAnbar set fldShomarsheJoz2=@fldShomareJoz  where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar
	else if @fldCountShomaresh=3
		update tblMoghayratMojoodieAnbar set fldShomarsheJoz3=@fldShomareJoz where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar

		if @fldShomareJoz=0 and @fldShomareshJozNahei=0
		begin
			if @tedad>0
			execute z145InsertMoghyratInfoForoosh @fldCodeAnbar,@fldCodeKala,@tedad,@fldDate,@fldTime
			else if @tedad<0
			execute z146InsertMoghyratInfoKharid @fldCodeAnbar,@fldCodeKala,@tedad,@fldDate,@fldTime
		end
	end
	else
	begin
	if @fldCountShomaresh=1
	begin
	insert into tblMoghayratMojoodieAnbar(fldCodeKala,fldCodeAnbar,fldShomarsheJoz1,fldShomarsheJoz2,fldShomarsheJoz3,fldShomarsheJozNehai)				
		values(@fldCodeKala,@fldCodeAnbar,@fldShomareJoz,null,null,@fldShomareshJozNahei)
	
	if @tedad=0
		begin
			execute z146InsertMoghyratInfoKharid @fldCodeAnbar,@fldCodeKala,@fldShomareJoz,@fldDate,@fldTime
		end
	else if @tedad>@fldShomareshJozNahei
		begin
			set @MaboTafavotTedad=@tedad-@fldShomareshJozNahei

				execute z145InsertMoghyratInfoForoosh @fldCodeAnbar,@fldCodeKala,@MaboTafavotTedad,@fldDate,@fldTime
		end
	else if @tedad<@fldShomareshJozNahei
		begin
			set @MaboTafavotTedad=@fldShomareshJozNahei-@tedad
			execute z146InsertMoghyratInfoKharid @fldCodeAnbar,@fldCodeKala,@MaboTafavotTedad,@fldDate,@fldTime
		end
		end
	else if @fldCountShomaresh=2
	begin
		update tblMoghayratMojoodieAnbar set fldShomarsheJoz2=@fldShomareJoz , fldShomarsheJozNehai=@fldShomareshJozNahei where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar
	if @tedad=0
		begin
			execute z146InsertMoghyratInfoKharid @fldCodeAnbar,@fldCodeKala,@fldShomareJoz,@fldDate,@fldTime
		end
	else if @tedad>@fldShomareshJozNahei
		begin
			set @MaboTafavotTedad=@tedad-@fldShomareshJozNahei

				execute z145InsertMoghyratInfoForoosh @fldCodeAnbar,@fldCodeKala,@MaboTafavotTedad,@fldDate,@fldTime
		end
	else if @tedad<@fldShomareshJozNahei
		begin
			set @MaboTafavotTedad=@fldShomareshJozNahei-@tedad
			execute z146InsertMoghyratInfoKharid @fldCodeAnbar,@fldCodeKala,@MaboTafavotTedad,@fldDate,@fldTime
		end
	end
	else if @fldCountShomaresh=3
	begin
		update tblMoghayratMojoodieAnbar set fldShomarsheJoz3=@fldShomareJoz,fldShomarsheJozNehai=@fldShomareshJozNahei where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar
	if @tedad=0
		begin
			execute z146InsertMoghyratInfoKharid @fldCodeAnbar,@fldCodeKala,@fldShomareJoz,@fldDate,@fldTime
		end
	else if @tedad>@fldShomareshJozNahei
		begin
			set @MaboTafavotTedad=@tedad-@fldShomareshJozNahei

				execute z145InsertMoghyratInfoForoosh @fldCodeAnbar,@fldCodeKala,@MaboTafavotTedad,@fldDate,@fldTime
		end
	else if @tedad<@fldShomareshJozNahei
		begin
			set @MaboTafavotTedad=@fldShomareshJozNahei-@tedad
			execute z146InsertMoghyratInfoKharid @fldCodeAnbar,@fldCodeKala,@MaboTafavotTedad,@fldDate,@fldTime
		end
	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

-- ===============================================
-- SP: [dbo].[z142ShowListMoghayratMojoodieAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.z142ShowListMoghayratMojoodieAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z142ShowListMoghayratMojoodieAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z142ShowListMoghayratMojoodieAnbar]

  @MiangineKharid bigint output,
  @JameTedad bigint output,
  @lngSumTedadeKolSahih bigint output,
  @Order int,
  @Filter int,
  @ListCodeKala varchar(5000)=null,
  @ListCodeAnbar varchar(5000)=null,
  @ListGroupKala varchar(5000)=null,
  @DateTa bigint,
  @NoeFee int
--@nn nvarchar(10)

as

IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin


create table #TempMojoodieAnbar(

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldTedadeVorood decimal(18, 2),
fldTedadeKhorooj decimal(18, 2),
fldTedadeJoz  decimal(18 ,2 ), 
fldTedadeKol decimal(18, 2), 
fldTedadDarKarton decimal(18, 2),
fldCodeAnbar int,
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20) COLLATE Persian_100_CI_AS,
fldShomarshTedadJoz1 decimal(18, 2),
fldShomarshTedadJoz2 decimal(18, 2),
fldShomarshTedadJoz3 decimal(18, 2),
fldMoghyrat1 decimal(18, 2),
fldMoghyrat2 decimal(18, 2),
fldMoghyrat3 decimal(18, 2),
fldShomareshJozNahei decimal(18, 2),
fldSabtShodeJoz decimal(18,2),
fldSabtShodeKol  nvarchar(100) collate Persian_100_CI_AS

)


create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 2),
SumKhorooj decimal(18, 2),
SumMande decimal(18, 2),
fldTedadDarKarton decimal(18, 2),
fldTedadKartonadadSahih decimal(18, 2),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldCodeAnbar int,
fldTedadVoroodKarton decimal(18, 2),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadKhoroojKarton decimal(18, 2),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh decimal(18, 2),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldKharid bigint,
fldforoosh bigint,
fldArzesheMojoodi bigint,
fldFeeForoosh bigint,
fldShomarshTedadJoz1 decimal(18, 2),
fldShomareTedadKol1 nvarchar(50),
fldShomarshTedadJoz2 decimal(18, 2),
fldShomareTedadKol2 nvarchar(50),
fldShomarshTedadJoz3 decimal(18, 2),
fldShomareTedadKol3 nvarchar(50),
fldMoghyrat1 decimal(18, 2),
fldMoghyrat2 decimal(18, 2),
fldMoghyrat3 decimal(18, 2),
fldCodeMoghyrat bigint,
fldMoghyratKol1 nvarchar(50),
fldMoghyratKol2 nvarchar(50),
fldMoghyratKol3 nvarchar(50),
fldShomareshJozNahei decimal(18, 2),
fldShomareshKolNahei nvarchar(50),
fldMandeKolKharid decimal(18, 2),
fldMandeKolForoosh decimal(18, 2),
fldSabtShodeJoz decimal(18,2),
fldSabtShodeKol  nvarchar(100) collate Persian_100_CI_AS
)
--delete from #TempMojoodieAnbar
 create table #TempMoghayratMojoodieAnbar(
	id			bigint,
	fldCodeKala bigint,
	fldCodeAnbar bigint,
	fldShomarshTedadJoz1 decimal(18, 2),
	fldShomarshTedadJoz2 decimal(18, 2),
	fldShomarshTedadJoz3 decimal(18, 2),
	fldMoghyrat1 decimal(18, 2),
	fldMoghyrat2 decimal(18, 2),
	fldMoghyrat3 decimal(18, 2),
	fldShomareshJozNahei decimal(18, 2)
 )

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 Where flddate<=@DateTa


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' ,fldTedadJozNahaei, 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            tblRizeTolid where fldType='mahsool' and flddate<=@DateTa



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 Where flddate<=@DateTa


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 Where flddate<=@DateTa


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,'havalehazine'
FROM            tblRizHavaleHazine Where flddate<=@DateTa


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,fldTedadJozAvalie , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeTolid where fldType='avalie' and flddate<=@DateTa


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 Where flddate<=@DateTa


update #TempMojoodieAnbar set fldFeeForoosh=tblKala.fldFeeForoosh from tblKala Where #TempMojoodieAnbar.fldCodeKala=tblKala.fldCodeKala

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


			 --update #TempMojoodieAnbar set  fldShomarshTedadJoz=tblMoghayratMojoodieAnbar.fldShomarsheJoz,fldMoghyrat=SUM(fldTedadeVorood - fldTedadeKhorooj)-tblMoghayratMojoodieAnbar.fldShomarsheJoz
				--	from tblMoghayratMojoodieAnbar 
				--	where #TempMojoodieAnbar.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala  and (#TempMojoodieAnbar.fldCodeAnbar IN (@ListCodeAnbar))

--فيلتر تا قبل از تاريخ 

-----------------------beit-mashal-----------------------------------



--update #TempMojoodieAnbar set  fldShomarshTedadJoz=tblMoghayratMojoodieAnbar.fldShomarsheJoz,fldMoghyrat=@SumTedadJoz-tblMoghayratMojoodieAnbar.fldShomarsheJoz
--from tblMoghayratMojoodieAnbar 
--where #TempMojoodieAnbar.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and #TempMojoodieAnbar.fldCodeAnbar=tblMoghayratMojoodieAnbar.fldCodeAnbar


-----------------------beit-mashal-----------------------------------




-----------------------beit-mashal-----------------------------------

 

--update #TempShowMojoodi set  fldShomarshTedadJoz=tblMoghayratMojoodieAnbar.fldShomarsheJoz,fldMoghyrat=SumMande-tblMoghayratMojoodieAnbar.fldShomarsheJoz,fldCountShomaresh=tblMoghayratMojoodieAnbar.fldCountShomaresh
--from tblMoghayratMojoodieAnbar 
--where #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 


-----------------------beit-mashal-----------------------------------

--Insert into #TempShowMojoodi
--	(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid,fldFeeForoosh,fldShomarshTedadJoz,fldMoghyrat)
--SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
--                         fldTedadDarKarton, fldGroupName, fldCodeGroup, #TempMojoodieAnbar.fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0 ,fldFeeForoosh,fldShomarshTedadJoz,fldMoghyrat
--FROM            #TempMojoodieAnbar inner join
--				#TempMoghayratMojoodieAnbar on #TempMoghayratMojoodieAnbar.fldCodeKala=#TempMojoodieAnbar.fldCodeKala
--GROUP BY #TempMojoodieAnbar.fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh

Insert into #TempShowMojoodi
	(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid,fldFeeForoosh)
SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
                         fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0,fldFeeForoosh
FROM            #TempMojoodieAnbar
GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh


-----------------------beit-mashal-----------------------------------

if @ListCodeAnbar <>''
begin
	update #TempShowMojoodi set  fldCodeMoghyrat=id,
								 fldShomarshTedadJoz1=tblMoghayratMojoodieAnbar.fldShomarsheJoz1,
								 fldShomarshTedadJoz2=tblMoghayratMojoodieAnbar.fldShomarsheJoz2,
								 fldShomarshTedadJoz3=tblMoghayratMojoodieAnbar.fldShomarsheJoz3,
								 fldShomareshJozNahei=tblMoghayratMojoodieAnbar.fldShomarsheJozNehai, 
								 fldMoghyrat1=SumMande-tblMoghayratMojoodieAnbar.fldShomarsheJoz1,
								 fldMoghyrat2=SumMande-tblMoghayratMojoodieAnbar.fldShomarsheJoz2,
								 fldMoghyrat3=SumMande-tblMoghayratMojoodieAnbar.fldShomarsheJoz3
		from tblMoghayratMojoodieAnbar 
		where #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and (Convert(varchar,tblMoghayratMojoodieAnbar.fldCodeAnbar) IN (@ListCodeAnbar)) 
		

		update #TempShowMojoodi Set fldShomareTedadKol1=Convert(varchar,floor(fldShomarshTedadJoz1 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz1, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 
		
		where fldTedadDarKarton>0 and fldShomarshTedadJoz1>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and (Convert(varchar,tblMoghayratMojoodieAnbar.fldCodeAnbar) IN (@ListCodeAnbar)) 

		update #TempShowMojoodi Set fldShomareTedadKol2=Convert(varchar,floor(fldShomarshTedadJoz2 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz2, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 
		where fldTedadDarKarton>0 and fldShomarshTedadJoz2>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and (Convert(varchar,tblMoghayratMojoodieAnbar.fldCodeAnbar) IN (@ListCodeAnbar)) 

		update #TempShowMojoodi Set fldShomareTedadKol3=Convert(varchar,floor(fldShomarshTedadJoz3 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz3, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 
		where fldTedadDarKarton>0 and fldShomarshTedadJoz3>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and (Convert(varchar,tblMoghayratMojoodieAnbar.fldCodeAnbar) IN (@ListCodeAnbar)) 
	--fldMoghyratKol1
	update #TempShowMojoodi Set fldMoghyratKol1=Convert(varchar,floor(fldMoghyrat1 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldMoghyrat1, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 	
		where fldTedadDarKarton>0 and fldMoghyrat1>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and (Convert(varchar,tblMoghayratMojoodieAnbar.fldCodeAnbar) IN (@ListCodeAnbar)) 
	--fldMoghyratKol2
		update #TempShowMojoodi Set fldMoghyratKol2=Convert(varchar,floor(fldMoghyrat2 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldMoghyrat2, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 	
		where fldTedadDarKarton>0 and fldMoghyrat2>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and (Convert(varchar,tblMoghayratMojoodieAnbar.fldCodeAnbar) IN (@ListCodeAnbar)) 
	--fldMoghyratKol3
		update #TempShowMojoodi Set fldMoghyratKol3=Convert(varchar,floor(fldMoghyrat3 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldMoghyrat3, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 	
		where fldTedadDarKarton>0 and fldMoghyrat3>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and (Convert(varchar,tblMoghayratMojoodieAnbar.fldCodeAnbar) IN (@ListCodeAnbar)) 
	--fldShomareshKolNahei
		update #TempShowMojoodi Set fldShomareshKolNahei=Convert(varchar,floor(fldShomareshJozNahei / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomareshJozNahei, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 	
		where fldTedadDarKarton>0 and fldShomareshJozNahei>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and (Convert(varchar,tblMoghayratMojoodieAnbar.fldCodeAnbar) IN (@ListCodeAnbar)) 

		end
else
begin
	update #TempShowMojoodi set  fldCodeMoghyrat=id,
								 fldShomarshTedadJoz1=tblMoghayratMojoodieAnbar.fldShomarsheJoz1,
								 fldShomarshTedadJoz2=tblMoghayratMojoodieAnbar.fldShomarsheJoz2,
								 fldShomarshTedadJoz3=tblMoghayratMojoodieAnbar.fldShomarsheJoz3,
								 fldShomareshJozNahei=tblMoghayratMojoodieAnbar.fldShomarsheJozNehai, 
								 fldMoghyrat1=SumMande-tblMoghayratMojoodieAnbar.fldShomarsheJoz1,
								 fldMoghyrat2=SumMande-tblMoghayratMojoodieAnbar.fldShomarsheJoz2,
								 fldMoghyrat3=SumMande-tblMoghayratMojoodieAnbar.fldShomarsheJoz3
		from tblMoghayratMojoodieAnbar 
		where #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 


		update #TempShowMojoodi Set fldShomareTedadKol1=Convert(varchar,floor(fldShomarshTedadJoz1 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz1, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 
		
		where fldTedadDarKarton>0 and fldShomarshTedadJoz1>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 

		update #TempShowMojoodi Set fldShomareTedadKol2=Convert(varchar,floor(fldShomarshTedadJoz2 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz2, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 
		where fldTedadDarKarton>0 and fldShomarshTedadJoz2>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 

		update #TempShowMojoodi Set fldShomareTedadKol3=Convert(varchar,floor(fldShomarshTedadJoz3 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz3, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 
		where fldTedadDarKarton>0 and fldShomarshTedadJoz3>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 
	--fldMoghyratKol1
	update #TempShowMojoodi Set fldMoghyratKol1=Convert(varchar,floor(fldMoghyrat1 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldMoghyrat1, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 	
		where fldTedadDarKarton>0 and fldMoghyrat1>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 
	--fldMoghyratKol2
		update #TempShowMojoodi Set fldMoghyratKol2=Convert(varchar,floor(fldMoghyrat2 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldMoghyrat2, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 	
		where fldTedadDarKarton>0 and fldMoghyrat2>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 
	--fldMoghyratKol3
		update #TempShowMojoodi Set fldMoghyratKol3=Convert(varchar,floor(fldMoghyrat3 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldMoghyrat3, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 	
		where fldTedadDarKarton>0 and fldMoghyrat3>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 
		--fldShomareshKolNahei
		update #TempShowMojoodi Set fldShomareshKolNahei=Convert(varchar,floor(fldShomareshJozNahei / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomareshJozNahei, fldTedadDarKarton) } ) + ' ' + fldNameVahed
		from tblMoghayratMojoodieAnbar 	
		where fldTedadDarKarton>0 and fldShomareshJozNahei>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 

		
end
--	-- پاک کردن دوره انبارگرداني که در گزارش نيستن
--if @fldCountShomaresh<>0
--		begin
--			delete from #TempShowMojoodi 
--		            where fldCountShomaresh=  @fldCountShomaresh
					
--		end

-----------------------beit-mashal-----------------------------------


--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

-- if @ListCodeAnbar <>''
--begin

--		update #TempShowMojoodi Set fldShomareTedadKol1=Convert(varchar,floor(fldShomarshTedadJoz1 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz1, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--		from tblMoghayratMojoodieAnbar 
		
--		where fldTedadDarKarton>0 and fldShomarshTedadJoz1>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and (Convert(varchar,tblMoghayratMojoodieAnbar.fldCodeAnbar) IN (@ListCodeAnbar)) 

--		update #TempShowMojoodi Set fldShomareTedadKol2=Convert(varchar,floor(fldShomarshTedadJoz2 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz2, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--		from tblMoghayratMojoodieAnbar 
--		where fldTedadDarKarton>0 and fldShomarshTedadJoz2>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and (Convert(varchar,tblMoghayratMojoodieAnbar.fldCodeAnbar) IN (@ListCodeAnbar)) 

--		update #TempShowMojoodi Set fldShomareTedadKol3=Convert(varchar,floor(fldShomarshTedadJoz3 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz3, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--		from tblMoghayratMojoodieAnbar 
--		where fldTedadDarKarton>0 and fldShomarshTedadJoz3>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala and (Convert(varchar,tblMoghayratMojoodieAnbar.fldCodeAnbar) IN (@ListCodeAnbar)) 
	

--		end
--else
--begin
	

--		update #TempShowMojoodi Set fldShomareTedadKol1=Convert(varchar,floor(fldShomarshTedadJoz1 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz1, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--		from tblMoghayratMojoodieAnbar 
		
--		where fldTedadDarKarton>0 and fldShomarshTedadJoz1>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 

--		update #TempShowMojoodi Set fldShomareTedadKol2=Convert(varchar,floor(fldShomarshTedadJoz2 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz2, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--		from tblMoghayratMojoodieAnbar 
--		where fldTedadDarKarton>0 and fldShomarshTedadJoz2>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 

--		update #TempShowMojoodi Set fldShomareTedadKol3=Convert(varchar,floor(fldShomarshTedadJoz3 / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(fldShomarshTedadJoz3, fldTedadDarKarton) } ) + ' ' + fldNameVahed
--		from tblMoghayratMojoodieAnbar 
--		where fldTedadDarKarton>0 and fldShomarshTedadJoz3>0 and #TempShowMojoodi.fldCodeKala=tblMoghayratMojoodieAnbar.fldCodeKala 
	
--end		

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 @NoeFeeKharid=1 --ميانگين خريد
--	update #TempShowMojoodi set fldKharid=tbl1.Miangin from
--	(SELECT        ROUND(SUM(fldFeeKol) / SUM(fldTedadJoz), 0) AS Miangin, fldCodeKala
--	FROM            tblRizeKharid
--	GROUP BY fldCodeKala
--	having         SUM(fldTedadJoz)>0
--	) as tbl1
--	where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala 
--else --آخرين في خريد
--	update #TempShowMojoodi set fldKharid=ROUND((tblRizeKharid.fldFeeKol) / (tblRizeKharid.fldTedadJoz), 0) from
--		tblRizeKharid where  tblRizeKharid.fldCodeKala=#TempShowMojoodi.fldCodeKala 
--if @NoeFee=1  --آخرين في خريد
--	begin

	update #TempShowMojoodi set fldKharid=ROUND((tblRizeKharid.fldFeeKol) / (tblRizeKharid.fldTedadJoz), 0) from
		tblRizeKharid where tblRizeKharid.fldTedadJoz > 0 AND  tblRizeKharid.fldCodeKala=#TempShowMojoodi.fldCodeKala 

	update #TempShowMojoodi set fldMandeKolKharid= fldKharid *fldShomareshJozNahei from
		tblRizeKharid  where ISNUMERIC(convert(varchar,fldShomareshJozNahei))=1 and  tblRizeKharid.fldCodeKala=#TempShowMojoodi.fldCodeKala 

	

--	end
--else --آخرين في فروش
	--begin
	update #TempShowMojoodi set fldforoosh=ROUND((tblRizeForoosh.fldFeeKol) / (tblRizeForoosh.fldTedadJoz), 0) from
		tblRizeForoosh where  tblRizeForoosh.fldCodeKala=#TempShowMojoodi.fldCodeKala  and tblRizeForoosh.fldTedadJoz<>0
	
	update #TempShowMojoodi set fldMandeKolForoosh=fldforoosh * fldShomareshJozNahei from
		tblRizeForoosh where ISNUMERIC(convert(varchar,fldShomareshJozNahei))=1 and  tblRizeForoosh.fldCodeKala=#TempShowMojoodi.fldCodeKala
	--end

	

--پاک کردن گروه کالاهايي که در گزارش نيستن
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)
update #TempShowMojoodi set fldTedadKartonadadSahih=(SumMande/fldTedadDarKarton)   Where fldTedadDarKarton>0
update #TempShowMojoodi set fldTedadKartonadadSahih=0 Where isnumeric(fldTedadKartonadadSahih)=0
set @lngSumTedadeKolSahih=(Select Sum(fldTedadKartonadadSahih) from #TempShowMojoodi)


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 @StrNoeMoghayerat nvarchar(50)
 declare @StrOrder nvarchar(50)
 declare @StrDoreh nvarchar(50)
 declare @Select nvarchar(500)

 --fldMoghyratKol1

 

 update #TempShowMojoodi set fldSabtShodeJoz=0
 update #TempShowMojoodi set fldSabtShodeJoz =tbl1.cnt from  (Select Sum(tblrizekharid.fldTedadJoz) as cnt,fldCodeKala from tblrizekharid Where fldtype='Moghayrat' group by fldCodeKala) as tbl1 where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala
 update #TempShowMojoodi set fldSabtShodeJoz =fldSabtShodeJoz-tbl1.cnt from  (Select Sum(tblrizeforoosh.fldTedadJoz) as cnt,fldCodeKala from tblrizeforoosh Where fldtype='Moghayrat' group by fldCodeKala) as tbl1 where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala
 update #TempShowMojoodi Set fldSabtShodeKol=Convert(varchar,floor(fldSabtShodeJoz / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec(18,2),fldSabtShodeJoz), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

 Set @Select='Select fldCodeKala ,fldNameKala ,SumMande ,fldTedadDarKarton,fldTedadDarKartonShow ,
	fldShomarshTedadJoz1,fldShomareTedadKol1,fldMoghyrat1,fldMoghyratKol1,
	fldShomarshTedadJoz2,fldShomareTedadKol2,fldMoghyrat2,fldMoghyratKol2,
	fldShomarshTedadJoz3,fldShomareTedadKol3,fldMoghyrat3,fldMoghyratKol3,
	fldCodeMoghyrat,fldShomareshJozNahei,fldShomareshKolNahei,fldKharid,fldforoosh,fldMandeKolKharid,fldMandeKolForoosh,fldSabtShodeJoz,fldSabtShodeKol from #TempShowMojoodi   '


--Select fldCodeKala ,fldNameKala ,SumMande ,fldTedadDarKarton,fldTedadDarKartonShow ,
--	fldShomarshTedadJoz1,fldShomareTedadKol1,fldMoghyrat1,fldMoghyratKol1,
--	fldShomarshTedadJoz2,fldShomareTedadKol2,fldMoghyrat2,fldMoghyratKol2,
--	fldShomarshTedadJoz3,fldShomareTedadKol3,fldMoghyrat3,fldMoghyratKol3,
--	fldCodeMoghyrat,fldShomareshJozNahei,fldShomareshKolNahei,fldKharid,fldforoosh,fldMandeKolKharid,fldMandeKolForoosh from #TempShowMojoodi where fldMoghyrat1=0 and fldMoghyrat2=0 and fldMoghyrat3=0 order by fldCodeKala

--Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	--fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid ,@strorder
	--from #TempShowMojoodi
--if @NoeMoghayerat=1--صفر
--	set @StrNoeMoghayerat=' where fldMoghyrat1=0 and fldMoghyrat2=0 and fldMoghyrat3=0 '
--else if @NoeMoghayerat=2---مثبت
--	set @StrNoeMoghayerat=' where fldMoghyrat1>0 and fldMoghyrat2>0 and fldMoghyrat3>0 '
--else if  @NoeMoghayerat=3--منفی
--	set @StrNoeMoghayerat=' where fldMoghyrat1<0 and fldMoghyrat2<0 and fldMoghyrat3<0 '



if @Order=0 
	Select fldCodeKala ,fldNameKala ,SumMande ,fldTedadDarKarton,fldTedadDarKartonShow ,
	fldShomarshTedadJoz1,fldShomareTedadKol1,fldMoghyrat1,fldMoghyratKol1,
	fldShomarshTedadJoz2,fldShomareTedadKol2,fldMoghyrat2,fldMoghyratKol2,
	fldShomarshTedadJoz3,fldShomareTedadKol3,fldMoghyrat3,fldMoghyratKol3,
	fldCodeMoghyrat,fldShomareshJozNahei,fldShomareshKolNahei,fldKharid,fldforoosh,fldMandeKolKharid,fldMandeKolForoosh,fldSabtShodeJoz,fldSabtShodeKol from #TempShowMojoodi order by fldCodeKala
else if @order=1 	
	Select fldCodeKala ,fldNameKala ,SumMande ,fldTedadDarKarton,fldTedadDarKartonShow ,
	fldShomarshTedadJoz1,fldShomareTedadKol1,fldMoghyrat1,fldMoghyratKol1,
	fldShomarshTedadJoz2,fldShomareTedadKol2,fldMoghyrat2,fldMoghyratKol2,
	fldShomarshTedadJoz3,fldShomareTedadKol3,fldMoghyrat3,fldMoghyratKol3,
	fldCodeMoghyrat,fldShomareshJozNahei,fldShomareshKolNahei,fldKharid,fldforoosh,fldMandeKolKharid,fldMandeKolForoosh,fldSabtShodeJoz,fldSabtShodeKol from #TempShowMojoodi order by fldNameKala
else if @order=2 
	Select fldCodeKala ,fldNameKala ,SumMande ,fldTedadDarKarton,fldTedadDarKartonShow ,
	fldShomarshTedadJoz1,fldShomareTedadKol1,fldMoghyrat1,fldMoghyratKol1,
	fldShomarshTedadJoz2,fldShomareTedadKol2,fldMoghyrat2,fldMoghyratKol2,
	fldShomarshTedadJoz3,fldShomareTedadKol3,fldMoghyrat3,fldMoghyratKol3,
	fldCodeMoghyrat,fldShomareshJozNahei,fldShomareshKolNahei,fldKharid,fldforoosh,fldMandeKolKharid,fldMandeKolForoosh,fldSabtShodeJoz,fldSabtShodeKol from #TempShowMojoodi order by SumMande desc
else if @order=3 
	Select fldCodeKala ,fldNameKala ,SumMande ,fldTedadDarKarton,fldTedadDarKartonShow ,
	fldShomarshTedadJoz1,fldShomareTedadKol1,fldMoghyrat1,fldMoghyratKol1,
	fldShomarshTedadJoz2,fldShomareTedadKol2,fldMoghyrat2,fldMoghyratKol2,
	fldShomarshTedadJoz3,fldShomareTedadKol3,fldMoghyrat3,fldMoghyratKol3,
	fldCodeMoghyrat,fldShomareshJozNahei,fldShomareshKolNahei,fldKharid,fldforoosh,fldMandeKolKharid,fldMandeKolForoosh,fldSabtShodeJoz,fldSabtShodeKol from #TempShowMojoodi order by SumMande asc
else if @order=4 
	Select fldCodeKala ,fldNameKala ,SumMande ,fldTedadDarKarton,fldTedadDarKartonShow ,
	fldShomarshTedadJoz1,fldShomareTedadKol1,fldMoghyrat1,fldMoghyratKol1,
	fldShomarshTedadJoz2,fldShomareTedadKol2,fldMoghyrat2,fldMoghyratKol2,
	fldShomarshTedadJoz3,fldShomareTedadKol3,fldMoghyrat3,fldMoghyratKol3,
	fldCodeMoghyrat,fldShomareshJozNahei,fldShomareshKolNahei,fldKharid,fldforoosh,fldMandeKolKharid,fldMandeKolForoosh,fldSabtShodeJoz,fldSabtShodeKol from #TempShowMojoodi order by fldKharid desc
else if @order=5 
	Select fldCodeKala ,fldNameKala ,SumMande ,fldTedadDarKarton,fldTedadDarKartonShow ,
	fldShomarshTedadJoz1,fldShomareTedadKol1,fldMoghyrat1,fldMoghyratKol1,
	fldShomarshTedadJoz2,fldShomareTedadKol2,fldMoghyrat2,fldMoghyratKol2,
	fldShomarshTedadJoz3,fldShomareTedadKol3,fldMoghyrat3,fldMoghyratKol3,
	fldCodeMoghyrat,fldShomareshJozNahei,fldShomareshKolNahei,fldKharid,fldforoosh,fldMandeKolKharid,fldMandeKolForoosh,fldSabtShodeJoz,fldSabtShodeKol from #TempShowMojoodi order by fldKharid asc
else if @Order=6
	Select fldCodeKala ,fldNameKala ,SumMande ,fldTedadDarKarton,fldTedadDarKartonShow ,
	fldShomarshTedadJoz1,fldShomareTedadKol1,fldMoghyrat1,fldMoghyratKol1,
	fldShomarshTedadJoz2,fldShomareTedadKol2,fldMoghyrat2,fldMoghyratKol2,
	fldShomarshTedadJoz3,fldShomareTedadKol3,fldMoghyrat3,fldMoghyratKol3,
	fldCodeMoghyrat,fldShomareshJozNahei,fldShomareshKolNahei,fldKharid,fldforoosh,fldMandeKolKharid,fldMandeKolForoosh,fldSabtShodeJoz,fldSabtShodeKol from #TempShowMojoodi order by fldGroupName desc
else if @Order=7
	Select fldCodeKala ,fldNameKala ,SumMande ,fldTedadDarKarton,fldTedadDarKartonShow ,
	fldShomarshTedadJoz1,fldShomareTedadKol1,fldMoghyrat1,fldMoghyratKol1,
	fldShomarshTedadJoz2,fldShomareTedadKol2,fldMoghyrat2,fldMoghyratKol2,
	fldShomarshTedadJoz3,fldShomareTedadKol3,fldMoghyrat3,fldMoghyratKol3,
	fldCodeMoghyrat,fldShomareshJozNahei,fldShomareshKolNahei,fldKharid,fldforoosh,fldMandeKolKharid,fldMandeKolForoosh,fldSabtShodeJoz,fldSabtShodeKol from #TempShowMojoodi order by fldCodeGroup asc


--else if @fldCountShomaresh=1 	
--	set @StrDoreh=' Where fldCountShomaresh='+ @fldCountShomaresh
--else if @fldCountShomaresh=2 
--	set @StrDoreh=' Where fldCountShomaresh='+ @fldCountShomaresh
--else if @fldCountShomaresh=3 
--	set @StrDoreh=' Where fldCountShomaresh='+ @fldCountShomaresh
	

--execute(@select  + @StrOrder  )

--if @Order=0 
--	set @StrOrder='  fldCodeKala'
--else if @order=1 	
--	set @StrOrder='  fldNameKala'
--else if @order=2 
--	set @StrOrder='  SumMande desc'
--else if @order=3 
--	set @StrOrder='  SumMande asc'
--else if @order=4 
--	set @StrOrder='  fldKharid desc'	
--else if @order=5 
--	set @StrOrder='  fldKharid asc'
--else if @Order=6
--	set @StrOrder=' fldGroupName desc'
--else if @Order=7
--	set @StrOrder='  fldCodeGroup asc'

--Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
--	fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldShomarshTedadJoz,fldMoghyrat from #TempShowMojoodi order by @StrOrder


	 

end
GO

-- ===============================================
-- SP: [dbo].[z143UpdateMoghyratAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.z143UpdateMoghyratAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z143UpdateMoghyratAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z143UpdateMoghyratAnbar]
@fldCodeMoghyrat bigint,
@fldShomareJoz bigint,
@fldCountShomaresh int,
@fldShomareshJozNahei bigint


as 

begin
	if @fldShomareshJozNahei<>0
	begin
	if @fldCountShomaresh=1
		update tblMoghayratMojoodieAnbar 
		set fldShomarsheJoz1=@fldShomareJoz ,fldShomarsheJozNehai=@fldShomareshJozNahei
		where id=@fldCodeMoghyrat
	--update tblMoghayratMojoodieAnbar set fldShomarsheJoz3=305,fldShomarsheJozNehai=305 where id=23
	else if @fldCountShomaresh=2
		update tblMoghayratMojoodieAnbar 
		set fldShomarsheJoz2=@fldShomareJoz ,fldShomarsheJozNehai=@fldShomareshJozNahei
		where id=@fldCodeMoghyrat
	else if @fldCountShomaresh=3
		update tblMoghayratMojoodieAnbar 
		set fldShomarsheJoz3=@fldShomareJoz ,fldShomarsheJozNehai=@fldShomareshJozNahei
		where id=@fldCodeMoghyrat
end
else
	begin
	if @fldCountShomaresh=1
		update tblMoghayratMojoodieAnbar 
		set fldShomarsheJoz1=@fldShomareJoz ,fldShomarsheJozNehai=0
		where id=@fldCodeMoghyrat
	--update tblMoghayratMojoodieAnbar set fldShomarsheJoz3=305,fldShomarsheJozNehai=305 where id=23
	else if @fldCountShomaresh=2
		update tblMoghayratMojoodieAnbar 
		set fldShomarsheJoz2=@fldShomareJoz ,fldShomarsheJozNehai=0
		where id=@fldCodeMoghyrat
	else if @fldCountShomaresh=3
		update tblMoghayratMojoodieAnbar 
		set fldShomarsheJoz3=@fldShomareJoz ,fldShomarsheJozNehai=0
		where id=@fldCodeMoghyrat
	end

end
GO

-- ===============================================
-- SP: [dbo].[z144DeleteMoghyratAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.z144DeleteMoghyratAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z144DeleteMoghyratAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z144DeleteMoghyratAnbar]
@strResult int output,
@fldCodeMoghyrat bigint,
@fldCountShomaresh int,
@fldCodeAnbar bigint,
@fldCodeKala bigint,
@Type nvarchar(50)

as 
begin
	declare @MaxRadif int,
			@count1 int,
			@count2 int,
			@ShomareshNahei bigint
	begin transaction AddRecord
		begin try
	if @fldCountShomaresh=1
		begin
		delete from tblMoghayratMojoodieAnbar  where id=@fldCodeMoghyrat

	    set @count1 =(select count(fldRadif) from tblRizeKharid where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat')
		if @count1 > 0
		begin
		delete from tblRizeKharid where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat'
		end
		  set @count2 =(select count(fldRadif) from tblRizeForoosh where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat')
		if @count2 > 0
		begin
		delete from tblRizeForoosh where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat'
		end

		end
	else if @fldCountShomaresh=2
		begin
		

		if @Type='Kharid'
		begin

			set @MaxRadif=(select Max(fldRadif) from tblRizeKharid where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat')
			delete from tblRizeKharid where fldRadif=@MaxRadif and fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat'
		end
		if @Type='Foroosh'
		begin
			set @MaxRadif=(select Max(fldRadif) from tblRizeForoosh where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat')
			delete from tblRizeForoosh where fldRadif=@MaxRadif and fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat'
		end
		set @ShomareshNahei=(select fldShomarsheJoz1 from tblMoghayratMojoodieAnbar where id=@fldCodeMoghyrat)
		update tblMoghayratMojoodieAnbar set fldShomarsheJoz2=null, fldShomarsheJozNehai=@ShomareshNahei where id=@fldCodeMoghyrat
		end
	else if @fldCountShomaresh=3
		begin
		
		
		if @Type='Kharid'
		begin
			set @MaxRadif=(select Max(fldRadif) from tblRizeKharid where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat')
			delete from tblRizeKharid where fldRadif=@MaxRadif and fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat'
		end
		if @Type='Foroosh'
		begin
			set @MaxRadif=(select Max(fldRadif) from tblRizeForoosh where fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat')
			delete from tblRizeForoosh where fldRadif=@MaxRadif and fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar and fldType='Moghayrat'
		end
		set @ShomareshNahei=(select fldShomarsheJoz2 from tblMoghayratMojoodieAnbar where id=@fldCodeMoghyrat)
		update tblMoghayratMojoodieAnbar set fldShomarsheJoz3=null, fldShomarsheJozNehai=@ShomareshNahei where id=@fldCodeMoghyrat
		end

		commit transaction AddRecord;
		
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult=1
			
				rollback transaction AddRecord;
			end
		end catch
end
GO

-- ===============================================
-- SP: [dbo].[z145InsertMoghyratInfoForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.z145InsertMoghyratInfoForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z145InsertMoghyratInfoForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z145InsertMoghyratInfoForoosh]





@fldCodeAnbar bigint,
@fldCodeKala bigint,
@fldTedadJoz decimal(18,2),
@fldDate bigint,
@fldTime nvarchar(20)

as 

begin
	--begin transaction AddRecord
	--	begin try
		
	declare 
	
		@maxRadif bigint,
		@count int

begin
 set	@count=(select count(fldRadif) from tblRizeForoosh where fldType='Moghayrat'  and fldCodeAnbar=@fldCodeAnbar )

	if @count=0
	begin



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,
								   fldShomareEnteghal,
								   fldShomareBargasht,
								   fldDateEngheza)
	values(0,
		   0,
		   0,
		   10000,
		   0,
		   1,
		   @fldCodeAnbar,
		   @fldCodeKala,
		   '',
		   0,
		   @fldTedadJoz,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   'Moghayrat',
		   @fldDate,
		   @fldTime,
		   0,
		   0,
		   0
		   )
 end
 else if @count<>0
 begin 
 set	@maxRadif=(select max(fldRadif) from tblRizeForoosh where fldType='Moghayrat' and fldCodeAnbar=@fldCodeAnbar)
 
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,
								   fldShomareEnteghal,
								   fldShomareBargasht,
								   fldDateEngheza)
	values(0,
		   0,
		   0,
		   10000,
		   0,
		   @maxRadif+1,
		   @fldCodeAnbar,
		   @fldCodeKala,
		   '',
		   0,
		   @fldTedadJoz,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   'Moghayrat',
		   @fldDate,
		   @fldTime,
		   0,
		   0,
		   0
		   )
 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

		end
GO

-- ===============================================
-- SP: [dbo].[z146InsertMoghyratInfoKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.z146InsertMoghyratInfoKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z146InsertMoghyratInfoKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z146InsertMoghyratInfoKharid]
@fldCodeAnbar bigint,
@fldCodeKala bigint,
@fldTedadJoz decimal(18,2),
@fldDate bigint,
@fldTime nvarchar(20)


as 

begin
	--begin transaction AddRecord
	--	begin try
		
	declare 
		@Count bigint,	
		@maxRadif bigint

	begin
	--select * from tblRizeKharid where fldType='Moghayrat'
	set	@count=(select count(fldRadif) from tblRizeKharid where fldType='Moghayrat' and fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar)
	
if @Count=0
	begin


 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,
								   fldShomareEnteghal,
								   fldDateEngheza)
	values(0,
		   0,
		   0,
		   10000,
		   0,
		   1,
		   @fldCodeAnbar,
		   @fldCodeKala,
		   '',
		   0,
		   @fldTedadJoz,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   'Moghayrat',
		   @fldDate,
		   @fldTime,
		   0,
		   0
		   )
 end

else if @Count<>0

 begin 
 set	@maxRadif=(select Max(fldRadif) from tblRizeKharid where fldType='Moghayrat' and fldCodeKala=@fldCodeKala and fldCodeAnbar=@fldCodeAnbar)
 
 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,
								   fldShomareEnteghal,
								   fldDateEngheza)
	values(0,
		   0,
		   0,
		   10000,
		   0,
		   @maxRadif+1,
		   @fldCodeAnbar,
		   @fldCodeKala,
		   '',
		   0,
		   @fldTedadJoz,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   0,
		   'Moghayrat',
		   @fldDate,
		   @fldTime,
		   0,
		   0
		   )
 end




	
end





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

-- ===============================================
-- SP: [dbo].[z147ShowListShomarshAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.z147ShowListShomarshAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z147ShowListShomarshAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z147ShowListShomarshAnbar]

  -- @MiangineKharid bigint output,
  --@JameTedad bigint output,
  --@lngSumTedadeKolSahih bigint output,

  @ListCodeKala varchar(5000)=null,
  @ListCodeAnbar varchar(5000)=null,
  @ListGroupKala varchar(5000)=null,
  @DateTa bigint



as

IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
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) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 0),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20) COLLATE Persian_100_CI_AS
)


create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 0),
SumKhorooj decimal(18, 0),
SumMande decimal(18, 0),
fldTedadDarKarton decimal(18, 0),
fldTedadKartonadadSahih decimal(18, 0),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldCodeAnbar int,
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldTedadVoroodKarton decimal(18, 0),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadKhoroojKarton decimal(18, 0),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh decimal(18, 0),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldKharid bigint,
fldArzesheMojoodi bigint,
fldFeeForoosh 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 Where flddate<=@DateTa


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' ,fldTedadJozNahaei, 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            tblRizeTolid where fldType='mahsool' and flddate<=@DateTa



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 Where flddate<=@DateTa


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 Where flddate<=@DateTa


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,fldTedadJozAvalie , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeTolid where fldType='avalie' and flddate<=@DateTa


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 Where flddate<=@DateTa



update #TempMojoodieAnbar set fldFeeForoosh=tblKala.fldFeeForoosh from tblKala Where #TempMojoodieAnbar.fldCodeKala=tblKala.fldCodeKala

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,fldFeeForoosh,fldCodeAnbar,fldNameAnbar)
SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
                         fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0,fldFeeForoosh,fldCodeAnbar,fldNameAnbar
FROM            #TempMojoodieAnbar
GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh,fldCodeAnbar,fldNameAnbar





--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



if @ListCodeAnbar <>''
		     begin
		      declare @StrDeleteAnbar varchar(5000)
		       set  @StrDeleteAnbar='delete from #TempShowMojoodi 
		            where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
					execute(@StrDeleteAnbar)
		     end


--فیلتر تا قبل از تاریخ 

--پاک کردن گروه کالاهایی که در گزارش نیستن
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
	


 



Select fldCodeKala ,fldNameKala,fldCodeAnbar,fldNameAnbar,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	  fldCodeGroup,fldGroupName from #TempShowMojoodi





	 

end
GO

-- ===============================================
-- SP: [dbo].[z148ShowList_ReportSarJameFoRoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.z148ShowList_ReportSarJameFoRoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z148ShowList_ReportSarJameFoRoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z148ShowList_ReportSarJameFoRoosh]
	@userCode bigint,
	@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
	delete from  #TempShow
 end
else 
begin
create table #TempRizeForoosh(

fldShomareSanad Nvarchar(30) COLLATE Persian_100_CI_AS,
fldShomareFactor Nvarchar(30) COLLATE Persian_100_CI_AS,
fldCodeTafsili Nvarchar(30) COLLATE Persian_100_CI_AS,
fldSharheTafzili Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeAnbar Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldCodeKala bigint,
fldNameKala Nvarchar(200) COLLATE Persian_100_CI_AS,
fldGhymatMasrafkonande Nvarchar(100) COLLATE Persian_100_CI_AS,
fldSharhKala Nvarchar(250) COLLATE Persian_100_CI_AS,
fldTedadCarton Nvarchar(100) COLLATE Persian_100_CI_AS, 
fldTedadJoz decimal(18,2),
fldFeeJoz decimal(18,2), 
fldFeeYekCarton decimal(18,2),
fldFeeKol decimal(18,2), 
fldFeeVahed1BadAzTakhfif decimal(18,2),
fldFeeVahed2BadAzTakhfif decimal(18,2), 
fldFeeKolBadAzTakhfif decimal(18,0), 
fldMablaghKhales decimal(18,2), 
fldType Nvarchar(50) COLLATE Persian_100_CI_AS, 
fldDate int, 
fldGroupId Nvarchar(30) COLLATE Persian_100_CI_AS,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeVasete Nvarchar(30) COLLATE Persian_100_CI_AS,
fldNameVasete Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldGroupNameAshkhas Nvarchar(200) COLLATE Persian_100_CI_AS,
fldTedadJozKarton decimal(18,2),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS
)



--fldCodeKala ,
--fldNameKala ,
--fldNameVahed,
--fldNameVahed2,
--fldTedadJoz,
--fldTedadJozKarton,
--fldTedadCarton,
--fldFeeJoz,
--fldFeeKol,
--fldFeeYekCarton,
--fldDarsadTakhfif,
--fldMablaghTakhfif,
--fldFeeVahed1BadAzTakhfif,
--fldFeeVahed2BadAzTakhfif,
--fldFeeKolBadAzTakhfif,
--fldArzeshAfzode,
--fldGhymatMasrafkonande, 
--fldGroupId,
--fldGroupName, 
--fldCodeAnbar, 
--fldNameAnbar,
--fldCodeTafsili,
--fldSharheTafzili

create table #TempShow(

fldCodeKala bigint,
fldNameKala Nvarchar(200) COLLATE Persian_100_CI_AS,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldTedadJoz  decimal(18,2),
fldTedadJozKarton decimal(18,2),
fldTedadCarton Nvarchar(100) COLLATE Persian_100_CI_AS,
fldFeeJoz decimal(18,2),
fldFeeYekCarton decimal(18,2), 
fldMablaghTakhfif decimal(18,2),
fldFeeVahed1BadAzTakhfif decimal(18,2),
fldFeeVahed2BadAzTakhfif decimal(18,2), 
fldFeeKolBadAzTakhfif decimal(18,2), 
fldGhymatMasrafkonande Nvarchar(100) COLLATE Persian_100_CI_AS,
fldGroupId Nvarchar(30) COLLATE Persian_100_CI_AS,
fldGroupName Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeAnbar Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS,
fldSharhKala Nvarchar(250) COLLATE Persian_100_CI_AS
)

end


	--declare @ListCodeKala varchar(5000)='',@ListGroupKala varchar(5000)='',@ListGroupAshkhas varchar(5000)='',@ListCodeAshkhas varchar(5000)='',@ListCodeVisitor varchar(5000)='',@ListCodeAnbar varchar(5000)='', @DateFrom varchar(8)='0',@DateTo varchar(8)='99999999', @FlagSort Varchar(5)='0'

update         tblRizeForoosh
set fldFeeVahed1BadAzTakhfif=(fldMablaghKhales-fldArzeshAfzode)/fldTedadJoz 
WHERE        (CONVERT(dec, fldMablaghKhales) <> fldTedadJoz * fldFeeVahed1BadAzTakhfif)


UPDATE       tblRizeBargashtAzForoosh
SET                fldFeeVahed1BadAzTakhfif = (fldMablaghKhales-fldArzeshAfzode) / fldTedadJoz
WHERE        (CONVERT(dec, fldMablaghKhales) <> fldTedadJoz * fldFeeVahed1BadAzTakhfif)

-- *************************************************************
-- *******Access Kala Limitation********************************
-- *************************************************************
declare @accessKala table(code bigint)
insert into @accessKala(code)
--exec ZSP_GetKalaAccesses @userCode
exec [ZSP_GetAccessableGroupKalaCode] @userCode
-- *************************************************************

-- *************************************************************
-- ******Group Ashkhas Limitation*******************************
-- *************************************************************
declare @accessAshkhasCodes table(code bigint)
insert into @accessAshkhasCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- *************************************************************


INSERT INTO #TempRizeForoosh(fldShomareSanad ,
fldShomareFactor ,
fldCodeTafsili ,
fldSharheTafzili , 
fldCodeAnbar , 
fldNameAnbar , 
fldCodeKala ,
fldNameKala ,
fldGhymatMasrafkonande,
fldSharhKala ,
fldTedadCarton , 
fldTedadJoz ,
fldFeeJoz , 
fldFeeYekCarton ,
fldFeeKol , 
fldFeeVahed1BadAzTakhfif ,
fldFeeVahed2BadAzTakhfif , 
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.fldFeeVahed1BadAzTakhfif, dbo.tblRizeForoosh.fldFeeVahed2BadAzTakhfif, 
                         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 
-- add kala access limitation
tblKala.fldCodeGroup in (select code from @accesskala) and
-- Group Ashkhas Limitation
fldCodeTafsili in (select code from @accessAshkhasCodes) and
						 dbo.tblRizeForoosh.fldType='Foroosh'  and dbo.tblRizeForoosh.fldDate  BETWEEN  @DateFrom  AND  @DateTo

INSERT INTO #TempRizeForoosh(fldShomareSanad ,
fldShomareFactor ,
fldCodeTafsili ,
fldSharheTafzili , 
fldCodeAnbar , 
fldNameAnbar , 
fldCodeKala ,
fldNameKala ,
fldGhymatMasrafkonande,
fldSharhKala ,
fldTedadCarton , 
fldTedadJoz ,
fldFeeJoz , 
fldFeeYekCarton ,
fldFeeKol , 
fldFeeVahed1BadAzTakhfif ,
fldFeeVahed2BadAzTakhfif , 
fldFeeKolBadAzTakhfif , 
fldMablaghKhales , 
fldType, 
fldDate, 
fldGroupId,
fldGroupName, 
fldCodeVasete,
fldNameVasete,
fldCodeGroupAshkhas,
fldGroupNameAshkhas,
fldTedadJozKarton,
fldNameVahed,
fldNameVahed2)



SELECT        dbo.tblRizeBargashtAzForoosh.fldShomareSanad, dbo.tblRizeBargashtAzForoosh.fldShomareFactor, dbo.tblRizeBargashtAzForoosh.fldCodeTafsili, tblTafzili_1.fldSharheTafzili, 
                         dbo.tblRizeBargashtAzForoosh.fldCodeAnbar, dbo.tblAnbar.fldNameAnbar, dbo.tblRizeBargashtAzForoosh.fldCodeKala, dbo.tblKala.fldNameKala, dbo.tblKala.fldGhymatMasrafkonande, 
                         dbo.tblRizeBargashtAzForoosh.fldSharhKala, dbo.tblRizeBargashtAzForoosh.fldTedadCarton,-1*ABS(dbo.tblRizeBargashtAzForoosh.fldTedadJoz), dbo.tblRizeBargashtAzForoosh.fldFeeJoz, 
                         dbo.tblRizeBargashtAzForoosh.fldFeeYekCarton, dbo.tblRizeBargashtAzForoosh.fldFeeKol, 
                         dbo.tblRizeBargashtAzForoosh.fldFeeVahed1BadAzTakhfif, dbo.tblRizeBargashtAzForoosh.fldFeeVahed2BadAzTakhfif, 
                         dbo.tblRizeBargashtAzForoosh.fldFeeKolBadAzTakhfif, dbo.tblRizeBargashtAzForoosh.fldMablaghKhales, dbo.tblRizeBargashtAzForoosh.fldType, dbo.tblRizeBargashtAzForoosh.fldDate, 
                         dbo.tblGroupKala.fldGroupId, dbo.tblGroupKala.fldGroupName, dbo.tblRizeBargashtAzForoosh.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.tblRizeBargashtAzForoosh INNER JOIN
                         dbo.tblAnbar ON dbo.tblRizeBargashtAzForoosh.fldCodeAnbar = dbo.tblAnbar.fldCode INNER JOIN
                         dbo.tblKala ON dbo.tblRizeBargashtAzForoosh.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.tblRizeBargashtAzForoosh.fldCodeTafsili = tblTafzili_1.fldCodeTafzili LEFT OUTER JOIN
                         dbo.tblTafzili ON dbo.tblRizeBargashtAzForoosh.fldCodeVasete = dbo.tblTafzili.fldCodeTafzili LEFT OUTER JOIN
                         dbo.tblGroupAshkhas AS tblGroupAshkhas_1 ON dbo.tblRizeBargashtAzForoosh.fldCodeVasete = tblGroupAshkhas_1.fldGroupId

						 where  
						 
						 -- add kala access limitation
tblKala.fldCodeGroup in (select code from @accesskala) and
-- Group Ashkhas Limitation
fldCodeTafsili in (select code from @accessAshkhasCodes) and
						 
						 dbo.tblRizeBargashtAzForoosh.fldType='BargashtAzForoosh'   ANd dbo.tblRizeBargashtAzForoosh.fldDate   BETWEEN  @DateFrom  AND  @DateTo

--SELECT sUM(fldFeeVahed1BadAzTakhfif*fldTedadJoz) from #TempRizeForoosh

         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


--update #TempRizeForoosh Set fldTedadJozKarton=Convert(varchar,floor( sum(convert(dec,fldFeeJoz)) / fldTedadJozKarton))  +  Convert(varchar, { fn MOD(Convert(dec,  sum(convert(dec,fldFeeJoz))), fldTedadJozKarton) } ) 
--	where fldTedadJozKarton>0

	
--if @FlagSort='0'
-- begin
-- select  

-- sum(convert(dec,fldTedadJoz)) as SumTedad, 
-- fldCodeKala,
--fldNameKala,
--case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
--case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end as fldNameVahed2,
--fldTedadJozKarton,
--fldFeeJoz,
--fldFeeYekCarton,
--fldDarsadTakhfif, 
--fldMablaghTakhfif,
--fldFeeVahed1BadAzTakhfif,
--fldFeeVahed2BadAzTakhfif, 
--fldArzeshAfzode, 
--fldGhymatMasrafkonande, 
--fldGroupId,
--fldGroupName, 
--fldCodeAnbar, 
--fldNameAnbar

----sum(convert(dec,fldFeeKol)),

--From #TempRizeForoosh 
--group by fldCodeKala,fldNameKala,fldNameVahed,fldNameVahed2,fldTedadJozKarton,fldFeeJoz,fldFeeYekCarton,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldGhymatMasrafkonande,fldGroupId,fldGroupName,fldCodeAnbar,fldNameAnbar


--	ORDER BY fldDate,Convert(dec,fldShomareFactor) ASC
-- end
 

-- --fldShomareFactor,fldCodeTafsili,fldSharheTafzili,fldCodeKala,fldNameKala,fldNameVahed,fldNameVahed2,fldTedadCarton,fldTedadJozKarton,fldFeeYekCarton,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldFeeKolBadAzTakhfif,fldArzeshAfzode,fldGhymatMasrafkonande,fldMablaghKhales,fldCodeGroupAshkhas,fldGroupNameAshkhas,fldGroupId,fldGroupName,fldCodeAnbar,fldNameAnbar,fldCodeVasete,fldNameVasete,fldDate,fldSharhKala,fldType
-- -- group by fldShomareSanad,fldShomareFactor,fldCodeTafsili,fldSharheTafzili,fldCodeKala,fldNameKala,fldNameVahed,fldNameVahed2,fldTedadCarton,fldTedadJozKarton,fldFeeYekCarton,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldFeeKolBadAzTakhfif,fldArzeshAfzode,fldGhymatMasrafkonande,fldMablaghKhales,fldCodeGroupAshkhas,fldGroupNameAshkhas,fldGroupId,fldGroupName,fldCodeAnbar,fldNameAnbar,fldCodeVasete,fldNameVasete,fldDate,fldSharhKala,fldType

 	
--if @FlagSort='1'
-- begin
-- select  
-- sum(convert(dec,fldTedadJoz)) as SumTedad, 
-- fldCodeKala,
--fldNameKala,
--case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
--case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end as fldNameVahed2,
--fldTedadJozKarton,
--fldFeeJoz,
--fldFeeYekCarton,
--fldDarsadTakhfif, 
--fldMablaghTakhfif,
--fldFeeVahed1BadAzTakhfif,
--fldFeeVahed2BadAzTakhfif, 
--fldArzeshAfzode, 
--fldGhymatMasrafkonande, 
--fldGroupId,
--fldGroupName, 
--fldCodeAnbar, 
--fldNameAnbar
----sum(convert(dec,fldFeeKol)),

--From #TempRizeForoosh 
--group by fldCodeKala,fldNameKala,fldNameVahed,fldNameVahed2,fldTedadJozKarton,fldFeeJoz,fldFeeYekCarton,fldDarsadTakhfif,fldMablaghTakhfif,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldArzeshAfzode,fldGhymatMasrafkonande,fldGroupId,fldGroupName,fldCodeAnbar,fldNameAnbar

--	ORDER BY Convert(dec,fldShomareSanad),Convert(dec,fldShomareFactor) ASC
-- end
 --declare @TedadCarton varchar
 --set @TedadCarton=( select Convert(varchar, convert(int,sum(convert(decimal,fldTedadJoz)) / convert(decimal,fldTedadJozKarton)))  +'-' + Convert(varchar, { fn MOD(Convert(dec, sum(convert(dec,fldTedadJoz))), convert(dec,fldTedadJozKarton)) } ) as fldTedadCarton
	--               from #TempRizeForoosh where fldTedadJozKarton>0 group by fldFeeJoz,fldTedadJozKarton)
	-- Convert(varchar, convert(int,sum(convert(decimal,fldTedadJoz)) / convert(decimal,fldTedadJozKarton)))  +'-' + Convert(varchar, { fn MOD(Convert(dec, sum(convert(dec,fldTedadJoz))), convert(dec,fldTedadJozKarton)) } ) as fldTedadCarton,
			   
--marashi



if @FlagSort='0'
 begin

-- select Sum(Convert(float,fldTedadJoz)*Convert(float,fldFeeVahed1BadAzTakhfif)) as Sss from #TempShow

  INSERT INTO #TempShow(
fldTedadJoz,
fldCodeKala ,
fldNameKala ,
fldNameVahed,
fldNameVahed2,
fldTedadJozKarton,
fldTedadCarton,
fldFeeJoz,
fldFeeYekCarton,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif,
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar,
fldSharhKala
)


  select  
  sum(convert(dec(18,2),fldTedadJoz)) as fldTedadJoz, 
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end as fldNameVahed2,
fldTedadJozKarton,
'0' as fldTedadCarton,
 Convert(float,fldFeeJoz) as fldFeeJoz,  
fldFeeYekCarton,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar,
fldSharhKala
--sum(convert(dec,fldFeeKol)),

From #TempRizeForoosh 
group by fldCodeKala,fldNameKala,fldNameVahed,fldNameVahed2,fldTedadJozKarton, Convert(float,fldFeeJoz),fldFeeYekCarton,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldGroupId,fldGroupName,fldCodeAnbar,fldNameAnbar
,fldSharhKala
	ORDER BY fldCodeKala ASC


--marashi
 end
 
 
 --select * from tblRizeForoosh where fldCodeKala=50067 and fldFeeVahed1BadAzTakhfif=2790648
 --select * from tblRizeForoosh where fldCodeKala=50067 and fldFeeVahed1BadAzTakhfif=2790648

if @FlagSort='1'
 begin

 INSERT INTO #TempShow(
fldTedadJoz,
fldCodeKala ,
fldNameKala ,
fldNameVahed,
fldNameVahed2,
fldTedadJozKarton,
fldTedadCarton,
fldFeeJoz,
fldFeeYekCarton,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif,
fldGhymatMasrafkonande, 
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar,
fldSharhKala
)


 select  
  sum(convert(dec(18,2),fldTedadJoz)) as fldTedadJoz, 
fldCodeKala,
fldNameKala,
case when fldNameVahed=N'انتخاب کنید' then '' else fldNameVahed end as fldNameVahed,
case when fldNameVahed2=N'انتخاب کنید' then '' else fldNameVahed2 end as fldNameVahed2,
fldTedadJozKarton,
'0' as fldTedadCarton,
 Convert(float,fldFeeJoz) as fldFeeJoz,  
fldFeeYekCarton,
fldFeeVahed1BadAzTakhfif,
fldFeeVahed2BadAzTakhfif, 
fldGhymatMasrafkonande, 
fldGroupId,
fldGroupName, 
fldCodeAnbar, 
fldNameAnbar,
fldSharhKala
--sum(convert(dec,fldFeeKol)),

From #TempRizeForoosh 
group by fldCodeKala,fldNameKala,fldNameVahed,fldNameVahed2,fldTedadJozKarton, Convert(float,fldFeeJoz),fldFeeYekCarton,fldFeeVahed1BadAzTakhfif,fldFeeVahed2BadAzTakhfif,fldGhymatMasrafkonande,fldGroupId,fldGroupName,fldCodeAnbar,fldNameAnbar
,fldSharhKala
	ORDER BY fldNameKala ASC
 end
 

 


 --select fldFeeJoz from #TempShow order by fldFeeJoz
--marashi
update #TempShow set fldFeeKolBadAzTakhfif=fldTedadJoz*fldFeeVahed1BadAzTakhfif
--
--update #TempShow set fldArzeshAfzode=fldTedadJoz*fldArzeshAfzode

update #TempShow Set fldTedadCarton=Convert(varchar,floor(convert(dec(18,2),fldTedadJoz) / convert(dec(18,2),fldTedadJozKarton))) + '-' +  Convert(varchar, { fn MOD(Convert(dec(18,2), fldTedadJoz), convert(dec(18,2),fldTedadJozKarton)) } ) 
where fldTedadJoz>0 and fldTedadJozKarton>0

update #TempShow Set fldTedadCarton=convert(varchar,(-1)*Convert(varchar,floor((-1)*convert(dec(18,2),fldTedadJoz) / convert(dec(18,2),fldTedadJozKarton)))) + ' کل ' +  Convert(varchar, { fn MOD(Convert(dec(18,2), fldTedadJoz), convert(dec(18,2),fldTedadJozKarton)) } )  +  ' جز '
where fldTedadJoz<0 and fldTedadJozKarton>0


update #TempShow Set fldFeeKolBadAzTakhfif=fldTedadJoz*Convert(dec,fldFeeVahed1BadAzTakhfif)
update #TempShow Set fldMablaghTakhfif=fldTedadJoz*(Convert(dec,fldFeeJoz)-Convert(dec,fldFeeVahed1BadAzTakhfif))

--update #TempShow set fldArzeshAfzode=convert(nvarchar,-1*convert(bigint,fldArzeshAfzode)) where convert(dec,fldFeeKolBadAzTakhfif)<0

if (@userCode >= 0 )
begin

select fldCodeKala,fldNameKala,fldNameVahed,fldNameVahed2,fldTedadJoz,fldTedadJozKarton,fldTedadCarton,Convert(decimal,fldFeeJoz) as fldFeeJoz,Convert(decimal,fldFeeYekCarton) as fldFeeYekCarton,fldMablaghTakhfif,Convert(decimal,fldFeeVahed1BadAzTakhfif) as fldFeeVahed1BadAzTakhfif,
Convert(decimal,fldFeeVahed2BadAzTakhfif) as fldFeeVahed2BadAzTakhfif,Convert(decimal,fldFeeKolBadAzTakhfif) as fldFeeKolBadAzTakhfif,Convert(decimal,fldGhymatMasrafkonande) as fldGhymatMasrafkonande,fldGroupId,fldGroupName,fldCodeAnbar,fldNameAnbar,fldSharhKala 
from #TempShow
--select Sum(Convert(float,fldTedadJoz)*Convert(float,fldFeeVahed1BadAzTakhfif)) as Sss from #TempShow

end
else begin

declare @accesscodes table(code bigint)

insert into @accesscodes(code)  
exec ZSP_GetKalaAccesses @userCode

select fldCodeKala,fldNameKala,fldNameVahed,fldNameVahed2,fldTedadJoz,fldTedadJozKarton,fldTedadCarton,Convert(decimal,fldFeeJoz) as fldFeeJoz,Convert(decimal,fldFeeYekCarton) as fldFeeYekCarton,fldMablaghTakhfif,Convert(decimal,fldFeeVahed1BadAzTakhfif) as fldFeeVahed1BadAzTakhfif,
Convert(decimal,fldFeeVahed2BadAzTakhfif) as fldFeeVahed2BadAzTakhfif,Convert(decimal,fldFeeKolBadAzTakhfif) as fldFeeKolBadAzTakhfif,Convert(decimal,fldGhymatMasrafkonande) as fldGhymatMasrafkonande,fldGroupId,fldGroupName,fldCodeAnbar,fldNameAnbar,fldSharhKala 
from #TempShow where  fldGroupId in (select code from @accesscodes)
end




END
GO

-- ===============================================
-- SP: [dbo].[z149ShowList_ReportAmalKardMoshtari]
-- ===============================================
IF OBJECT_ID(N'dbo.z149ShowList_ReportAmalKardMoshtari', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z149ShowList_ReportAmalKardMoshtari] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z149ShowList_ReportAmalKardMoshtari]

	@ListGroupAshkhas varchar(5000)=null,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeAnbar varchar(5000)=null
as
   
	
BEGIN
	
	SET NOCOUNT ON;


-- ----------------------------------------
-- -----------------------------------------TempTable In Below Code

IF OBJECT_ID('tempdb..#TempRizeAmalKardMoshtari') IS NOT NULL
 begin
	delete from     #TempRizeAmalKardMoshtari
	delete from     #TempShowAmalKardMoshtari
	delete from     #TempSumForoosh
	delete from     #TempSumBargashtAzForoosh		
	delete from 	#TempSumCheckDaryafti
	delete from 	#TempSumCheckBargashti
	delete from 	#TempSumCheckVosoolShode
	delete from 	#TempSumCheckVosoolShodeNaShode
	delete from 	#TempSumCheckPardakhti
	delete from     #TempGroupAshkhas
	delete from     #TempAnbar
 end
else 
--Nvarchar(30) COLLATE Persian_100_CI_AS,
begin

create table #TempGroupAshkhas(
fldCodeTafzili bigint,
fldCodeGroup bigint, 
fldGroupName nvarchar(50)  COLLATE Persian_100_CI_AS
)
create table #TempAnbar(
fldCodeTafzili bigint,
fldCodeAnbar bigint, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS
)
create table #TempSumForoosh(
fldCodeTafzili bigint,
fldMablaghForoosh decimal,
fldTedadJozForoosh decimal
)
create table #TempSumBargashtAzForoosh(
fldCodeTafzili bigint,
fldMablaghBargasht decimal,
fldTedadJozBargasht decimal
)
create table #TempSumCheckDaryafti(
fldCodeTafzili bigint,
fldMablaghCheckDaryafti decimal
)
create table #TempSumCheckBargashti(
fldCodeTafzili bigint,
fldMablaghCheckBargashti decimal
)
create table #TempSumCheckVosoolShode(
fldCodeTafzili bigint,
fldMablaghCheckVosoolShode decimal
)
create table #TempSumCheckVosoolShodeNaShode(
fldCodeTafzili bigint,
fldMablaghCheckVosoolShodeNaShode decimal
)
create table #TempSumCheckPardakhti(
fldCodeTafzili bigint,
fldMablaghCheckPardakhti decimal
)

Create table #TempRizeAmalKardMoshtari(
fldCodeTafzili bigint,
fldSharheTafzili nvarchar(200) COLLATE Persian_100_CI_AS,
fldTedadJozForoosh decimal,
fldMablaghForoosh decimal,
fldTedadJozBargasht decimal,
fldMablaghBargasht decimal,
fldMablaghCheckDaryafti decimal,
fldMablaghCheckBargashti decimal,
fldMablaghCheckVosoolShode decimal,
fldMablaghCheckVosoolNaShode decimal,
fldMablaghCheckPardakhti decimal,
fldCodeGroupAshkhas Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldGroupNameAshkhas Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS
)
Create table #TempShowAmalKardMoshtari(
fldCodeTafzili Nvarchar(30) COLLATE Persian_100_CI_AS,
fldSharheTafzili nvarchar(200) COLLATE Persian_100_CI_AS,
fldTedadJozForoosh decimal,
fldMablaghForoosh decimal,
fldTedadJozBargasht decimal,
fldMablaghBargasht decimal,
fldMablaghCheckDaryafti decimal,
fldMablaghCheckBargashti decimal,
fldMablaghCheckVosoolShode decimal,
fldMablaghCheckVosoolNaShode decimal,
fldMablaghCheckPardakhti decimal,
fldCodeGroupAshkhas Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldGroupNameAshkhas Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS
)

end


insert into #TempSumForoosh(fldCodeTafzili,fldMablaghForoosh,fldTedadJozForoosh)
			(select fldCodeTafsili,Sum(fldMablaghKhales),Sum(fldTedadJoz) from tblRizeForoosh group by fldCodeTafsili)

insert into #TempSumBargashtAzForoosh(fldCodeTafzili,fldMablaghBargasht,fldTedadJozBargasht)
			(select fldCodeTafsili,Sum(fldMablaghKhales),Sum(fldTedadJoz) from tblRizeBargashtAzForoosh group by fldCodeTafsili)

insert into #TempSumCheckDaryafti(fldCodeTafzili,fldMablaghCheckDaryafti)
			(select fldCodeSahebeCheck,Sum(fldMablagh) from tblCheckeDaryafti group by fldCodeSahebeCheck)

insert into #TempSumCheckBargashti(fldCodeTafzili,fldMablaghCheckBargashti)
			(select fldCodeSahebeCheck,Sum(fldMablagh) from tblCheckeDaryafti where fldVaziat='Bargasht' group by fldCodeSahebeCheck )

insert into #TempSumCheckVosoolShode(fldCodeTafzili,fldMablaghCheckVosoolShode)
			(select fldCodeSahebeCheck,Sum(fldMablagh) from tblCheckeDaryafti where fldVaziat='Vosool' group by fldCodeSahebeCheck )

insert into #TempSumCheckVosoolShodeNaShode(fldCodeTafzili,fldMablaghCheckVosoolShodeNaShode)
			(select fldCodeSahebeCheck,Sum(fldMablagh) from tblCheckeDaryafti where fldVaziat<>'Vosool' group by fldCodeSahebeCheck )

insert into #TempSumCheckPardakhti(fldCodeTafzili,fldMablaghCheckPardakhti)
			(select fldCodeSahebeCheck,Sum(fldMablagh) from tblCheckePardakhti  group by fldCodeSahebeCheck )

insert into #TempGroupAshkhas(fldCodeTafzili,fldCodeGroup,fldGroupName)
(SELECT        tblRizeForoosh.fldCodeTafsili, tblGroupAshkhas.fldGroupId, tblGroupAshkhas.fldGroupName
FROM            tblTafzili INNER JOIN
                         tblRizeForoosh ON tblTafzili.fldCodeTafziliBigInt = tblRizeForoosh.fldCodeTafsili INNER JOIN
                         tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
GROUP BY tblRizeForoosh.fldCodeTafsili, tblGroupAshkhas.fldGroupId, tblGroupAshkhas.fldGroupName)


insert into #TempAnbar(fldCodeTafzili,fldCodeAnbar,fldNameAnbar)
(SELECT        tblRizeForoosh.fldCodeTafsili, tblRizeForoosh.fldCodeAnbar, tblAnbar.fldNameAnbar
FROM            tblTafzili INNER JOIN
                         tblRizeForoosh ON tblTafzili.fldCodeTafziliBigInt = tblRizeForoosh.fldCodeTafsili INNER JOIN
                         tblAnbar ON tblRizeForoosh.fldCodeAnbar = tblAnbar.fldCode
GROUP BY tblRizeForoosh.fldCodeTafsili, tblRizeForoosh.fldCodeAnbar, tblAnbar.fldNameAnbar)



insert into #TempRizeAmalKardMoshtari(
						fldCodeTafzili,
						fldSharheTafzili,
						fldTedadJozForoosh,				
						fldMablaghForoosh,
						fldMablaghBargasht,
						fldTedadJozBargasht,
						fldMablaghCheckDaryafti,
						fldMablaghCheckBargashti,
						fldMablaghCheckVosoolShode,
						fldMablaghCheckVosoolNaShode,
						fldMablaghCheckPardakhti
						)

select #TempSumForoosh.fldCodeTafzili,
		    tblTafzili.fldSharheTafzili,
			fldTedadJozForoosh,
			fldMablaghForoosh,			
		   0 as fldMablaghBargasht,
		   0 as fldTedadJozBargasht,			
		   0 as fldMablaghCheckDaryafti,
		   0 as fldMablaghCheckBargashti,
		   0 as fldMablaghCheckVosoolShode,
		   0 as fldMablaghCheckVosoolNaShode,
		   0 as fldMablaghCheckPardakhti

from #TempSumForoosh inner join
	tblTafzili on #TempSumForoosh.fldCodeTafzili=tblTafzili.fldCodeTafzili 
-------SumBargashtAzForoosh---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghBargasht = #TempSumBargashtAzForoosh.fldMablaghBargasht,
		#TempRizeAmalKardMoshtari.fldTedadJozBargasht = #TempSumBargashtAzForoosh.fldTedadJozBargasht
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumBargashtAzForoosh on #TempSumBargashtAzForoosh.fldCodeTafzili=SI.fldCodeTafzili 

-------CheckDaryafti---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghCheckDaryafti =#TempSumCheckDaryafti.fldMablaghCheckDaryafti
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumCheckDaryafti on #TempSumCheckDaryafti.fldCodeTafzili=SI.fldCodeTafzili 
-------CheckBargashti---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghCheckBargashti =#TempSumCheckBargashti.fldMablaghCheckBargashti
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumCheckBargashti on #TempSumCheckBargashti.fldCodeTafzili=SI.fldCodeTafzili 
-------CheckVosoolShode---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghCheckVosoolShode =#TempSumCheckVosoolShode.fldMablaghCheckVosoolShode
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumCheckVosoolShode on #TempSumCheckVosoolShode.fldCodeTafzili=SI.fldCodeTafzili 
				
-------CheckVosoolShodeNaShode---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghCheckVosoolNaShode =#TempSumCheckVosoolShodeNaShode.fldMablaghCheckVosoolShodeNaShode
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumCheckVosoolShodeNaShode on #TempSumCheckVosoolShodeNaShode.fldCodeTafzili=SI.fldCodeTafzili 
-------CheckPardakhti---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghCheckPardakhti =#TempSumCheckPardakhti.fldMablaghCheckPardakhti
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumCheckPardakhti on #TempSumCheckPardakhti.fldCodeTafzili=SI.fldCodeTafzili 
-------GroupAshkhas---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldCodeGroupAshkhas =#TempGroupAshkhas.fldCodeGroup,
		#TempRizeAmalKardMoshtari.fldGroupNameAshkhas=#TempGroupAshkhas.fldGroupName
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempGroupAshkhas on #TempGroupAshkhas.fldCodeTafzili=SI.fldCodeTafzili 
-------GroupAshkhas---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldCodeAnbar =#TempAnbar.fldCodeAnbar,
		#TempRizeAmalKardMoshtari.fldNameAnbar =#TempAnbar.fldNameAnbar
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempAnbar on #TempAnbar.fldCodeTafzili=SI.fldCodeTafzili 
					

insert into #TempShowAmalKardMoshtari(
		fldCodeTafzili,
	fldSharheTafzili,
	fldTedadJozForoosh,
	fldMablaghForoosh,
	fldTedadJozBargasht,
	fldMablaghBargasht,
	fldMablaghCheckDaryafti,
	fldMablaghCheckBargashti,
	fldMablaghCheckVosoolShode,
	fldMablaghCheckVosoolNaShode,
	fldMablaghCheckPardakhti,
	fldCodeGroupAshkhas, 
	fldGroupNameAshkhas,
	fldCodeAnbar, 
	fldNameAnbar )
	(select  
	fldCodeTafzili,
	fldSharheTafzili,
	fldTedadJozForoosh,
	fldMablaghForoosh,
	fldTedadJozBargasht,
	fldMablaghBargasht,
	fldMablaghCheckDaryafti,
	fldMablaghCheckBargashti,
	fldMablaghCheckVosoolShode,
	fldMablaghCheckVosoolNaShode,
	fldMablaghCheckPardakhti,
	fldCodeGroupAshkhas, 
	fldGroupNameAshkhas,
	fldCodeAnbar, 
	fldNameAnbar 
from #TempRizeAmalKardMoshtari
	)


		   if @ListCodeAshkhas <>''
		    begin
		     declare @StrDeleteAshkhas varchar(5000)
		      set  @StrDeleteAshkhas='delete from #TempShowAmalKardMoshtari 
		            where fldCodeTafzili NOT IN ('+ @ListCodeAshkhas +')'
					execute(@StrDeleteAshkhas)
		    end


			if @ListGroupAshkhas<>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShowAmalKardMoshtari
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end

			if @ListCodeAnbar <>''
		     begin
		      declare @StrDeleteAnbar varchar(5000)
		       set  @StrDeleteAnbar='delete from #TempShowAmalKardMoshtari
		            where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
					execute(@StrDeleteAnbar)
		     end


		 select  
	fldCodeTafzili,
	fldSharheTafzili,
	fldTedadJozForoosh,
	fldMablaghForoosh,
	fldTedadJozBargasht,
	fldMablaghBargasht,
	fldMablaghCheckDaryafti,
	fldMablaghCheckBargashti,
	fldMablaghCheckVosoolShode,
	fldMablaghCheckVosoolNaShode,
	fldMablaghCheckPardakhti,
	fldCodeGroupAshkhas, 
	fldGroupNameAshkhas,
	fldCodeAnbar, 
	fldNameAnbar 
from #TempShowAmalKardMoshtari
 



END
GO

-- ===============================================
-- SP: [dbo].[z149ShowList_ReportAmalKardMoshtari_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z149ShowList_ReportAmalKardMoshtari_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z149ShowList_ReportAmalKardMoshtari_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z149ShowList_ReportAmalKardMoshtari_WithUserCode]
	
	@ListGroupAshkhas varchar(5000)=null,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeAnbar varchar(5000)=null,
	@userCode bigint,
	@DateAz bigint,
	@DateTa bigint,
	@Sort nvarchar(20)
as
   
	
BEGIN
	
	SET NOCOUNT ON;


-- ----------------------------------------
-- -----------------------------------------TempTable In Below Code

IF OBJECT_ID('tempdb..#TempRizeAmalKardMoshtari') IS NOT NULL
 begin
	delete from     #TempRizeAmalKardMoshtari
	delete from     #TempShowAmalKardMoshtari
	delete from     #TempSumForoosh
	delete from     #TempSumBargashtAzForoosh		
	delete from 	#TempSumCheckDaryafti
	delete from 	#TempSumCheckBargashti
	delete from 	#TempSumCheckVosoolShode
	delete from 	#TempSumCheckVosoolShodeNaShode
	delete from 	#TempSumCheckPardakhti
	delete from     #TempGroupAshkhas
	delete from     #TempAnbar
 end
else 
--Nvarchar(30) COLLATE Persian_100_CI_AS,
begin

create table #TempGroupAshkhas(
fldCodeTafzili bigint,
fldCodeGroup bigint, 
fldGroupName nvarchar(50)  COLLATE Persian_100_CI_AS
)
create table #TempAnbar(
fldCodeTafzili bigint,
fldCodeAnbar bigint, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS
)
create table #TempSumForoosh(
fldCodeTafzili bigint,
fldMablaghForoosh decimal,
fldTedadJozForoosh decimal
)
create table #TempSumBargashtAzForoosh(
fldCodeTafzili bigint,
fldMablaghBargasht decimal,
fldTedadJozBargasht decimal
)
create table #TempSumCheckDaryafti(
fldCodeTafzili bigint,
fldMablaghCheckDaryafti decimal
)
create table #TempSumCheckBargashti(
fldCodeTafzili bigint,
fldMablaghCheckBargashti decimal
)
create table #TempSumCheckVosoolShode(
fldCodeTafzili bigint,
fldMablaghCheckVosoolShode decimal
)
create table #TempSumCheckVosoolShodeNaShode(
fldCodeTafzili bigint,
fldMablaghCheckVosoolShodeNaShode decimal
)
create table #TempSumCheckPardakhti(
fldCodeTafzili bigint,
fldMablaghCheckPardakhti decimal
)

Create table #TempRizeAmalKardMoshtari(
fldCodeTafzili bigint,
fldSharheTafzili nvarchar(200) COLLATE Persian_100_CI_AS,
fldTedadJozForoosh decimal,
fldMablaghForoosh decimal,
fldTedadJozBargasht decimal,
fldMablaghBargasht decimal,
fldMablaghCheckDaryafti decimal,
fldMablaghCheckBargashti decimal,
fldMablaghCheckVosoolShode decimal,
fldMablaghCheckVosoolNaShode decimal,
fldMablaghCheckPardakhti decimal,
fldCodeGroupAshkhas Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldGroupNameAshkhas Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS
)
Create table #TempShowAmalKardMoshtari(
fldCodeTafzili Nvarchar(30) COLLATE Persian_100_CI_AS,
fldSharheTafzili nvarchar(200) COLLATE Persian_100_CI_AS,
fldTedadJozForoosh decimal,
fldMablaghForoosh decimal,
fldTedadJozBargasht decimal,
fldMablaghBargasht decimal,
fldMablaghCheckDaryafti decimal,
fldMablaghCheckBargashti decimal,
fldMablaghCheckVosoolShode decimal,
fldMablaghCheckVosoolNaShode decimal,
fldMablaghCheckPardakhti decimal,
fldCodeGroupAshkhas Nvarchar(30) COLLATE Persian_100_CI_AS, 
fldGroupNameAshkhas Nvarchar(200) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint, 
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS
)

end


insert into #TempSumForoosh(fldCodeTafzili,fldMablaghForoosh,fldTedadJozForoosh)
			(select fldCodeTafsili,Sum(fldMablaghKhales),Sum(fldTedadJoz) from tblRizeForoosh where fldDate between @DateAz and @DateTa group by fldCodeTafsili)

insert into #TempSumBargashtAzForoosh(fldCodeTafzili,fldMablaghBargasht,fldTedadJozBargasht)
			(select fldCodeTafsili,Sum(fldMablaghKhales),Sum(fldTedadJoz) from tblRizeBargashtAzForoosh  where fldDate between @DateAz and @DateTa  group by fldCodeTafsili)

insert into #TempSumCheckDaryafti(fldCodeTafzili,fldMablaghCheckDaryafti)
			(select fldCodeSahebeCheck,Sum(fldMablagh) from tblCheckeDaryafti  where  fldDateDaryaft  between @DateAz and @DateTa group by fldCodeSahebeCheck)

insert into #TempSumCheckBargashti(fldCodeTafzili,fldMablaghCheckBargashti)
			(select fldCodeSahebeCheck,Sum(fldMablagh) from tblCheckeDaryafti where  fldDateBargasht between @DateAz and @DateTa  and fldVaziat='Bargasht' group by fldCodeSahebeCheck )

insert into #TempSumCheckVosoolShode(fldCodeTafzili,fldMablaghCheckVosoolShode)
			(select fldCodeSahebeCheck,Sum(fldMablagh) from tblCheckeDaryafti  where fldDateVosool between @DateAz and @DateTa  and fldVaziat='Vosool' group by fldCodeSahebeCheck )

insert into #TempSumCheckVosoolShodeNaShode(fldCodeTafzili,fldMablaghCheckVosoolShodeNaShode)
			(select fldCodeSahebeCheck,Sum(fldMablagh) from tblCheckeDaryafti  where fldDateDaryaft between @DateAz and @DateTa and fldVaziat<>'Vosool' group by fldCodeSahebeCheck )

insert into #TempSumCheckPardakhti(fldCodeTafzili,fldMablaghCheckPardakhti)
			(select fldCodeSahebeCheck,Sum(fldMablagh) from tblCheckePardakhti  where fldDatePardakht between @DateAz and @DateTa  group by fldCodeSahebeCheck )

insert into #TempGroupAshkhas(fldCodeTafzili,fldCodeGroup,fldGroupName)
(SELECT        tblRizeForoosh.fldCodeTafsili, tblGroupAshkhas.fldGroupId, tblGroupAshkhas.fldGroupName
FROM            tblTafzili INNER JOIN
                         tblRizeForoosh ON tblTafzili.fldCodeTafziliBigInt = tblRizeForoosh.fldCodeTafsili INNER JOIN
                         tblGroupAshkhas ON tblTafzili.fldCodeGroup = tblGroupAshkhas.fldGroupId
						  where fldDate between @DateAz and @DateTa 
GROUP BY tblRizeForoosh.fldCodeTafsili, tblGroupAshkhas.fldGroupId, tblGroupAshkhas.fldGroupName)


insert into #TempAnbar(fldCodeTafzili,fldCodeAnbar,fldNameAnbar)
(SELECT        tblRizeForoosh.fldCodeTafsili, tblRizeForoosh.fldCodeAnbar, tblAnbar.fldNameAnbar
FROM            tblTafzili INNER JOIN
                         tblRizeForoosh ON tblTafzili.fldCodeTafziliBigInt = tblRizeForoosh.fldCodeTafsili INNER JOIN
                         tblAnbar ON tblRizeForoosh.fldCodeAnbar = tblAnbar.fldCode
						  where fldDate between @DateAz and @DateTa 
GROUP BY tblRizeForoosh.fldCodeTafsili, tblRizeForoosh.fldCodeAnbar, tblAnbar.fldNameAnbar)



insert into #TempRizeAmalKardMoshtari(
						fldCodeTafzili,
						fldSharheTafzili,
						fldTedadJozForoosh,				
						fldMablaghForoosh,
						fldMablaghBargasht,
						fldTedadJozBargasht,
						fldMablaghCheckDaryafti,
						fldMablaghCheckBargashti,
						fldMablaghCheckVosoolShode,
						fldMablaghCheckVosoolNaShode,
						fldMablaghCheckPardakhti
						)

select #TempSumForoosh.fldCodeTafzili,
		    tblTafzili.fldSharheTafzili,
			fldTedadJozForoosh,
			fldMablaghForoosh,			
		   0 as fldMablaghBargasht,
		   0 as fldTedadJozBargasht,			
		   0 as fldMablaghCheckDaryafti,
		   0 as fldMablaghCheckBargashti,
		   0 as fldMablaghCheckVosoolShode,
		   0 as fldMablaghCheckVosoolNaShode,
		   0 as fldMablaghCheckPardakhti

from #TempSumForoosh inner join
	tblTafzili on #TempSumForoosh.fldCodeTafzili=tblTafzili.fldCodeTafzili 


	
insert into #TempRizeAmalKardMoshtari(
						fldCodeTafzili,
						fldSharheTafzili,
						fldTedadJozForoosh,				
						fldMablaghForoosh,
						fldMablaghBargasht,
						fldTedadJozBargasht,
						fldMablaghCheckDaryafti,
						fldMablaghCheckBargashti,
						fldMablaghCheckVosoolShode,
						fldMablaghCheckVosoolNaShode,
						fldMablaghCheckPardakhti
						)
	select fldCodeTafzili,fldSharheTafzili,0,0,0,0,0,0,0,0,0 from tblTafzili where fldCodeTafzili not in (select fldCodeTafzili from #TempRizeAmalKardMoshtari)


-------SumBargashtAzForoosh---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghBargasht = #TempSumBargashtAzForoosh.fldMablaghBargasht,
		#TempRizeAmalKardMoshtari.fldTedadJozBargasht = #TempSumBargashtAzForoosh.fldTedadJozBargasht
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumBargashtAzForoosh on #TempSumBargashtAzForoosh.fldCodeTafzili=SI.fldCodeTafzili 

-------CheckDaryafti---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghCheckDaryafti =#TempSumCheckDaryafti.fldMablaghCheckDaryafti
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumCheckDaryafti on #TempSumCheckDaryafti.fldCodeTafzili=SI.fldCodeTafzili 
-------CheckBargashti---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghCheckBargashti =#TempSumCheckBargashti.fldMablaghCheckBargashti
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumCheckBargashti on #TempSumCheckBargashti.fldCodeTafzili=SI.fldCodeTafzili 
-------CheckVosoolShode---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghCheckVosoolShode =#TempSumCheckVosoolShode.fldMablaghCheckVosoolShode
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumCheckVosoolShode on #TempSumCheckVosoolShode.fldCodeTafzili=SI.fldCodeTafzili 
				
-------CheckVosoolShodeNaShode---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghCheckVosoolNaShode =#TempSumCheckVosoolShodeNaShode.fldMablaghCheckVosoolShodeNaShode
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumCheckVosoolShodeNaShode on #TempSumCheckVosoolShodeNaShode.fldCodeTafzili=SI.fldCodeTafzili 
-------CheckPardakhti---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldMablaghCheckPardakhti =#TempSumCheckPardakhti.fldMablaghCheckPardakhti
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempSumCheckPardakhti on #TempSumCheckPardakhti.fldCodeTafzili=SI.fldCodeTafzili 
-------GroupAshkhas---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldCodeGroupAshkhas =#TempGroupAshkhas.fldCodeGroup,
		#TempRizeAmalKardMoshtari.fldGroupNameAshkhas=#TempGroupAshkhas.fldGroupName
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempGroupAshkhas on #TempGroupAshkhas.fldCodeTafzili=SI.fldCodeTafzili 
-------GroupAshkhas---------
update #TempRizeAmalKardMoshtari 
		set 
		#TempRizeAmalKardMoshtari.fldCodeAnbar =#TempAnbar.fldCodeAnbar,
		#TempRizeAmalKardMoshtari.fldNameAnbar =#TempAnbar.fldNameAnbar
		from
		#TempRizeAmalKardMoshtari SI
		INNER JOIN
		#TempAnbar on #TempAnbar.fldCodeTafzili=SI.fldCodeTafzili 
	
	
-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################


insert into #TempShowAmalKardMoshtari(
		fldCodeTafzili,
	fldSharheTafzili,
	fldTedadJozForoosh,
	fldMablaghForoosh,
	fldTedadJozBargasht,
	fldMablaghBargasht,
	fldMablaghCheckDaryafti,
	fldMablaghCheckBargashti,
	fldMablaghCheckVosoolShode,
	fldMablaghCheckVosoolNaShode,
	fldMablaghCheckPardakhti,
	fldCodeGroupAshkhas, 
	fldGroupNameAshkhas,
	fldCodeAnbar, 
	fldNameAnbar )
	(select  
	fldCodeTafzili,
	fldSharheTafzili,
	fldTedadJozForoosh,
	fldMablaghForoosh,
	fldTedadJozBargasht,
	fldMablaghBargasht,
	fldMablaghCheckDaryafti,
	fldMablaghCheckBargashti,
	fldMablaghCheckVosoolShode,
	fldMablaghCheckVosoolNaShode,
	fldMablaghCheckPardakhti,
	fldCodeGroupAshkhas, 
	fldGroupNameAshkhas,
	fldCodeAnbar, 
	fldNameAnbar 
from #TempRizeAmalKardMoshtari
	)
	update #TempShowAmalKardMoshtari set fldCodeGroupAshkhas =tblTafzili.fldCodeGroup from tblTafzili where #TempShowAmalKardMoshtari.fldCodeGroupAshkhas=tblTafzili.fldCodeGroup
	update #TempShowAmalKardMoshtari set fldCodeGroupAshkhas =100 where fldCodeGroupAshkhas   is null

		   if @ListCodeAshkhas <>''
		    begin
		     declare @StrDeleteAshkhas varchar(5000)
		      set  @StrDeleteAshkhas='delete from #TempShowAmalKardMoshtari 
		            where fldCodeTafzili NOT IN ('+ @ListCodeAshkhas +')'
					execute(@StrDeleteAshkhas)
		    end


			if @ListGroupAshkhas<>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShowAmalKardMoshtari
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end

			if @ListCodeAnbar <>''
		     begin
		      declare @StrDeleteAnbar varchar(5000)
		       set  @StrDeleteAnbar='delete from #TempShowAmalKardMoshtari
		            where fldCodeAnbar NOT IN ('+ @ListCodeAnbar +')'
					execute(@StrDeleteAnbar)
		     end

if @Sort='mablaghforoosh'
	select  
		fldCodeTafzili,
		fldSharheTafzili,
		fldTedadJozForoosh,
		fldMablaghForoosh,
		fldTedadJozBargasht,
		fldMablaghBargasht,
		fldMablaghCheckDaryafti,
		fldMablaghCheckBargashti,
		fldMablaghCheckVosoolShode,
		fldMablaghCheckVosoolNaShode,
		fldMablaghCheckPardakhti,
		fldCodeGroupAshkhas, 
		fldGroupNameAshkhas,
		fldCodeAnbar, 
		fldNameAnbar 
	from #TempShowAmalKardMoshtari
	where 
	-- ##################### Group Ashkhas Limitation
	fldCodeTafzili in (select code from @accessCodes) order by fldMablaghForoosh desc
 
if @Sort='tedadjozforoosh'
	select  
		fldCodeTafzili,
		fldSharheTafzili,
		fldTedadJozForoosh,
		fldMablaghForoosh,
		fldTedadJozBargasht,
		fldMablaghBargasht,
		fldMablaghCheckDaryafti,
		fldMablaghCheckBargashti,
		fldMablaghCheckVosoolShode,
		fldMablaghCheckVosoolNaShode,
		fldMablaghCheckPardakhti,
		fldCodeGroupAshkhas, 
		fldGroupNameAshkhas,
		fldCodeAnbar, 
		fldNameAnbar 
	from #TempShowAmalKardMoshtari
	where 
	-- ##################### Group Ashkhas Limitation
	fldCodeTafzili in (select code from @accessCodes) order by fldTedadJozForoosh desc

if @Sort='mablaghbargasht'
	select  
		fldCodeTafzili,
		fldSharheTafzili,
		fldTedadJozForoosh,
		fldMablaghForoosh,
		fldTedadJozBargasht,
		fldMablaghBargasht,
		fldMablaghCheckDaryafti,
		fldMablaghCheckBargashti,
		fldMablaghCheckVosoolShode,
		fldMablaghCheckVosoolNaShode,
		fldMablaghCheckPardakhti,
		fldCodeGroupAshkhas, 
		fldGroupNameAshkhas,
		fldCodeAnbar, 
		fldNameAnbar 
	from #TempShowAmalKardMoshtari
	where 
	-- ##################### Group Ashkhas Limitation
	fldCodeTafzili in (select code from @accessCodes) order by fldMablaghBargasht desc

if @Sort='fldtedadjozbargasht'
	select  
		fldCodeTafzili,
		fldSharheTafzili,
		fldTedadJozForoosh,
		fldMablaghForoosh,
		fldTedadJozBargasht,
		fldMablaghBargasht,
		fldMablaghCheckDaryafti,
		fldMablaghCheckBargashti,
		fldMablaghCheckVosoolShode,
		fldMablaghCheckVosoolNaShode,
		fldMablaghCheckPardakhti,
		fldCodeGroupAshkhas, 
		fldGroupNameAshkhas,
		fldCodeAnbar, 
		fldNameAnbar 
	from #TempShowAmalKardMoshtari
	where 
	-- ##################### Group Ashkhas Limitation
	fldCodeTafzili in (select code from @accessCodes) order by fldTedadJozBargasht desc

if @Sort='codetafzili'
	select  
		fldCodeTafzili,
		fldSharheTafzili,
		fldTedadJozForoosh,
		fldMablaghForoosh,
		fldTedadJozBargasht,
		fldMablaghBargasht,
		fldMablaghCheckDaryafti,
		fldMablaghCheckBargashti,
		fldMablaghCheckVosoolShode,
		fldMablaghCheckVosoolNaShode,
		fldMablaghCheckPardakhti,
		fldCodeGroupAshkhas, 
		fldGroupNameAshkhas,
		fldCodeAnbar, 
		fldNameAnbar 
	from #TempShowAmalKardMoshtari
	where 
	-- ##################### Group Ashkhas Limitation
	fldCodeTafzili in (select code from @accessCodes) order by fldCodeTafzili 
END
GO

-- ===============================================
-- SP: [dbo].[z150ListeKalaBedooneMojoodi]
-- ===============================================
IF OBJECT_ID(N'dbo.z150ListeKalaBedooneMojoodi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z150ListeKalaBedooneMojoodi] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z150ListeKalaBedooneMojoodi]
	-- Add the parameters for the stored procedure here
	
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.

create table #TempShowMojoodi2(

fldCodeKala bigint,
SumVorood decimal(18, 2),
SumKhorooj decimal(18, 2),
SumMande decimal(18, 2),
Mande nvarchar(18),
mandeeee nvarchar(10),
fldTedadDarKarton decimal(18, 2),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadVoroodKarton decimal(18, 2),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldTedadKhoroojKarton decimal(18, 2),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh decimal(18, 2),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldKharid bigint,
fldFeeForoosh money,
fldArzesheMojoodi bigint
)

Insert into #TempShowMojoodi2
	(fldCodeKala,fldNameKala,fldNameVahed,fldNameVahed2,SumMande,fldTedadDarKarton, fldGroupName, fldTedadDarKartonShow)
SELECT        dbo.tblKala.fldCodeKala , dbo.tblKala.fldNameKala, dbo.tblVahed.fldNameVahed, tblVahed_1.fldNameVahed AS fldNameVahed2,0 as SumMande,0,'',''                         
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


select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,Mande as SumMande,fldFeeForoosh,fldCodeGroup,fldTedadDarKartonShow from #TempShowMojoodi2	 



END
GO

-- ===============================================
-- SP: [dbo].[z150ShowList_ReportAshkhasFactorNashode]
-- ===============================================
IF OBJECT_ID(N'dbo.z150ShowList_ReportAshkhasFactorNashode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z150ShowList_ReportAshkhasFactorNashode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z150ShowList_ReportAshkhasFactorNashode]

	@ListGroupAshkhas varchar(5000)=null,
	@DateAz varchar(50),
	@DateTa varchar(50)
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;



create table #TempShow(
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldGroupAshkhasShow Nvarchar(100) COLLATE Persian_100_CI_AS,
fldAddress Nvarchar(200) COLLATE Persian_100_CI_AS,
fldShomare Nvarchar(30) COLLATE Persian_100_CI_AS
)
delete #TempShow

insert into #TempShow(fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas,fldGroupAshkhasShow,fldAddress)
SELECT   fldCodeTafzili,fldSharheTafzili, fldCodeGroup,dbo.tblGroupAshkhas.fldGroupName, fldAddress                
FROM            tblTafzili inner join
				dbo.tblGroupAshkhas on dbo.tblTafzili.fldCodeGroup=dbo.tblGroupAshkhas.fldGroupId
WHERE        (fldCodeTafzili NOT IN
                             (SELECT DISTINCT fldCodeTafsili
                                FROM tblRizeForoosh where fldType='foroosh' and fldDate between @DateAz and @DateTa)) AND (fldCodeNoe = '1')



		if @ListGroupAshkhas<>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end

	
	
SELECT  ROW_NUMBER() OVER(ORDER BY fldCodeTafzili) as fldRadif,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas,fldGroupAshkhasShow,fldAddress               
FROM            #TempShow 

END
GO

-- ===============================================
-- SP: [dbo].[z150ShowList_ReportAshkhasFactorNashode_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z150ShowList_ReportAshkhasFactorNashode_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z150ShowList_ReportAshkhasFactorNashode_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z150ShowList_ReportAshkhasFactorNashode_WithUserCode]

	@ListGroupAshkhas varchar(5000)=null,
	@ListCodeVisitor varchar(5000)=null,
	@DateAz varchar(50),
	@DateTa varchar(50),
	@userCode bigint
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;



create table #TempShow(
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(250) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldGroupAshkhasShow Nvarchar(100) COLLATE Persian_100_CI_AS,
fldAddress Nvarchar(200) COLLATE Persian_100_CI_AS,
fldShomare Nvarchar(30) COLLATE Persian_100_CI_AS,
fldCodevasete bigint,
fldNameVisitor NVarchar(250) COLLATE Persian_100_CI_AS,
)
delete #TempShow

insert into #TempShow(fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas,fldGroupAshkhasShow,fldAddress,fldCodevasete)
SELECT   fldCodeTafzili,fldSharheTafzili, fldCodeGroup,dbo.tblGroupAshkhas.fldGroupName, fldAddress,fldVisitor                
FROM            tblTafzili inner join
				dbo.tblGroupAshkhas on dbo.tblTafzili.fldCodeGroup=dbo.tblGroupAshkhas.fldGroupId
WHERE        (fldCodeTafzili NOT IN
                             (SELECT DISTINCT fldCodeTafsili
                                FROM tblRizeForoosh where fldType='foroosh' and fldDate between @DateAz and @DateTa)) AND (fldCodeNoe = '1')



		if @ListGroupAshkhas<>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end

		if @ListCodeVisitor<>''
		     begin
		      declare @StrDeleteVisitor varchar(5000)
		       set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListCodeVisitor + ''
					execute(@StrDeleteVisitor)
		     end

	
		update #TempShow set fldshomare=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempShow.fldCodetafzili=tbl5.fldCodeTafzili


		update #TempShow set fldNameVisitor=tblTafzili.fldSharheTafzili from tblTafzili where #TempShow.fldCodevasete=tblTafzili.fldCodeTafzili and #TempShow.fldCodevasete<>0
-- ###############################################################
-- ###########Group Ashkhas Limitation############################
-- ###############################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ###############################################################
	
SELECT  ROW_NUMBER() OVER(ORDER BY fldCodeTafzili) as fldRadif,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas,fldGroupAshkhasShow,fldShomare,fldAddress,fldCodevasete,fldNameVisitor               
FROM            #TempShow 
where fldCodeTafzili in (select code from @accessCodes)

END
GO

-- ===============================================
-- SP: [dbo].[z151BahayeTamamShodeForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.z151BahayeTamamShodeForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z151BahayeTamamShodeForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z151BahayeTamamShodeForoosh]

@lngDateFrom bigint,
@lngDateUntil bigint,
@SumBahayeTamamShode bigint output,
@MablagheEbtedayeDore bigint output,
@MablagheKharidTeyeDore bigint output,
@MablagheBargashtAzKharid bigint output,
@MablaghePayanDore bigint 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 #tmpGardesheKala
		(
			CodeKala bigint,
			CodeGroup bigint,
			CodeAnbar bigint,
			NameGroup nvarchar(100) collate Persian_100_CI_AS,
			NameKala nvarchar(100) collate Persian_100_CI_AS,
			NameAnbar nvarchar(100) collate Persian_100_CI_AS,
			TedadDarKarton bigint,

			MablagheEbteda bigint,
			TedadeEbteda bigint,
			TedadKartonEbteda nvarchar(100) collate Persian_100_CI_AS,

			MablagheKharid bigint,
			TedadeKharid bigint,
			TedadKartonKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheBargashtAzKharid bigint,
			TedadeBargashtAzKharid bigint,
			TedadKartonBargashtAzKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheKhalesKharid bigint,
			TedadeKhalesKharid bigint,
			TedadKartonKhalesKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheForoosh bigint,
			TedadeForoosh bigint,
			TedadeKartonForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablagheBargashtAzForoosh bigint,
			TedadeBargashtAzForoosh bigint,
			TedadeKartonBargashtAzForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablagheKhalesForoosh bigint,
			TedadeKhalesForoosh bigint,
			TedadKartonKhalesForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablaghePayan bigint,
			TedadePayan bigint,
			TedadeKartonPayan nvarchar(100) collate Persian_100_CI_AS,

			BahayeTamamShodeForoosh bigint,
			SoodeKala bigint
		)


		insert into #tmpGardesheKala
			(CodeKala,CodeGroup,NameKala,TedadDarKarton)
			Select  fldCodeKala,fldCodeGroup,fldNameKala,fldTedadJoz 
				from  tblKala

		--update #tmpGardesheKala set TedadeEbteda=Sum(tblRizeKharid.fldTedadeJoz) from tblRizeKharid where #tmpGardesheKala.CodeKala=tblRizeKharid.fldCodeKala group by tblRizeKharid.fldCodeKala

		update           #tmpGardesheKala
			set NameGroup = tblGroupKala.fldGroupName from tblGroupKala Where CodeGroup=tblGroupKala.fldGroupId

		--####ابتدای دوره####
		update           #tmpGardesheKala
			set tedadeEbteda=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='mojodi_ebteda_doreh'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala

		
		update #tmpGardesheKala 
			set MablagheEbteda=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldFeeKol) as Sum1 from tblRizekharid Where fldType='mojodi_ebteda_doreh'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 
			--mojodi_ebteda_doreh



		----کارتن و عدد
		--update #tmpGardesheKala Set TedadKartonEbteda=Convert(varchar,floor(tedadeEbteda / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeEbteda, TedadDarKarton) } ) 
		--	where TedadDarKarton>0
		--######################
		--######خرید#####
		update           #tmpGardesheKala
			set tedadekharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='kharid'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set Mablaghekharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizekharid Where fldType='kharid'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		----کارتن و عدد
		--update #tmpGardesheKala Set TedadKartonkharid=Convert(varchar,floor(TedadeKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeKharid, TedadDarKarton) } ) 
		--	where TedadDarKarton>0
		--#######################
		--######برگشت از خرید#####
		update           #tmpGardesheKala
			set tedadeBargashtAzkharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeBargashtAzkharid Where fldType='bargashtazkharid'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheBargashtAzKharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeBargashtAzkharid Where fldType='bargashtazkharid'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		----کارتن و عدد
		--update #tmpGardesheKala Set TedadKartonBargashtAzkharid=Convert(varchar,floor(TedadeBargashtAzKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeBargashtAzKharid, TedadDarKarton) } ) 
		--	where TedadDarKarton>0
		--#######################

		--######فروش#####
		update           #tmpGardesheKala
			set TedadeForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeForoosh Where fldType='Foroosh'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeForoosh Where fldType='Foroosh'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		----کارتن و عدد
		--update #tmpGardesheKala Set TedadeKartonForoosh=Convert(varchar,floor(TedadeForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeForoosh, TedadDarKarton) } ) 
		--	where TedadDarKarton>0

	--######برگشت از فروش#####
		update           #tmpGardesheKala
			set TedadeBargashtAzForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeBargashtAzForoosh Where fldType='bargashtazforoosh'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheBargashtAzForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeBargashtAzForoosh Where fldType='bargashtazforoosh'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		----کارتن و عدد
		--update #tmpGardesheKala Set TedadeKartonForoosh=Convert(varchar,floor(TedadeForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeForoosh, TedadDarKarton) } ) 
		--	where TedadDarKarton>0
		--#######################
		--#######################
		update           #tmpGardesheKala
			set TedadeEbteda=0 Where TedadeEbteda is null  
		update           #tmpGardesheKala
			set TedadeKharid=0 Where TedadeKharid is null
		update           #tmpGardesheKala
			set TedadeBargashtAzKharid=0 Where TedadeBargashtAzKharid is null
		update           #tmpGardesheKala
			set TedadeForoosh=0 Where TedadeForoosh is null
		update           #tmpGardesheKala
			set TedadeBargashtAzForoosh=0 Where TedadeBargashtAzForoosh is null
		update           #tmpGardesheKala
			set MablagheEbteda=0 Where MablagheEbteda is null
		update           #tmpGardesheKala
			set MablagheKharid=0 Where MablagheKharid is null
		update           #tmpGardesheKala
			set MablagheForoosh=0 Where MablagheForoosh is null
		update           #tmpGardesheKala
			set MablaghePayan=0 Where MablaghePayan is null
		update           #tmpGardesheKala
			set bahayetamamshodeforoosh=0 Where bahayetamamshodeforoosh is null
		update           #tmpGardesheKala
			set SoodeKala=0 Where SoodeKala is null
		update           #tmpGardesheKala
			set MablagheBargashtAzKharid=0 Where MablagheBargashtAzKharid is null


		--######خالص خرید#######
		update           #tmpGardesheKala
			set TedadeKhalesKharid=TedadeKharid-TedadeBargashtAzKharid
		update #tmpGardesheKala Set TedadKartonKhalesKharid=Convert(varchar,floor(TedadeKhalesKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalesKharid, TedadDarKarton) } ) 
			where TedadDarKarton>0

		update #tmpGardesheKala Set MablagheKhalesKharid=MablagheKharid-MablagheBargashtAzKharid

		--######خالص فروش#######
		update           #tmpGardesheKala
			set TedadeKhalesForoosh=TedadeForoosh-TedadeBargashtAzForoosh
		update #tmpGardesheKala Set TedadKartonKhalesForoosh=Convert(varchar,floor(TedadeKhalesForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalesForoosh, TedadDarKarton) } ) 
			where TedadDarKarton>0

		update #tmpGardesheKala Set MablagheKhalesForoosh=MablagheForoosh-MablagheBargashtAzForoosh
		--######پایان دوره#####
		update           #tmpGardesheKala
			set tedadePayan=TedadeEbteda+TedadeKharid+TedadeBargashtAzForoosh-TedadeForoosh-TedadeBargashtAzKharid
		update #tmpGardesheKala
			set MablaghePayan=(MablagheEbteda+MablagheKharid)/(TedadeEbteda+TedadeKharid)*tedadePayan
			where TedadeEbteda+TedadeKharid>0
		----کارتن و عدد
		--update #tmpGardesheKala Set TedadeKartonPayan=Convert(varchar,floor(TedadePayan/ TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadePayan, TedadDarKarton) } ) 
		--	where TedadDarKarton>0
		--#######################

		--####انتقال بین انبار و تولید کنترل شود#######

		   
		delete  #tmpGardesheKala where  TedadePayan<0 

		


		update #tmpGardesheKala set BahayeTamamShodeForoosh=MablagheEbteda+MablagheKharid-MablagheBargashtAzKharid-MablaghePayan

		--select BahayeTamamShodeForoosh,MablagheEbteda,MablagheKharid,MablagheBargashtAzKharid,MablaghePayan from #tmpGardesheKala
		--select Sum(MablagheEbteda)   from #tmpGardesheKala
		--select BahayeTamamShodeForoosh from #tmpGardesheKala
		--update #tmpGardesheKala set SoodeKala=MablagheForoosh-BahayeTamamShodeForoosh
		set @MablagheEbtedayeDore=(Select SUM(MablagheEbteda) from #tmpGardesheKala )
		set @MablagheKharidTeyeDore=(Select SUM(MablagheKharid) from #tmpGardesheKala )
		set @MablagheBargashtAzKharid=(Select SUM(MablagheBargashtAzKharid) from #tmpGardesheKala )
		set @MablaghePayanDore=(Select SUM(MablaghePayan) from #tmpGardesheKala )

		update           #tmpGardesheKala
			set bahayetamamshodeforoosh=0 Where bahayetamamshodeforoosh is null

		set @SumBahayeTamamShode=(Select SUM(BahayeTamamShodeForoosh) from #tmpGardesheKala)

		--Select MablagheEbteda,MablagheKharid,MablaghePayan, SUM(BahayeTamamShodeForoosh) as SumBahayeTamamShodeForooshrafte from #tmpGardesheKala
		--Select ROW_NUMBER() OVER(ORDER BY CodeKala ) AS Row, CodeKala,NameGroup,NameKala,TedadDarKarton,TedadeEbteda,TedadKartonEbteda,MablagheEbteda,
		--	TedadeKharid,TedadKartonKharid,MablagheKharid,TedadeForoosh,TedadeKartonForoosh,MablagheForoosh,TedadePayan,TedadeKartonPayan,MablaghePayan,BahayeTamamShodeForoosh ,SoodeKala
		--from #tmpGardesheKala
	
END
GO

-- ===============================================
-- SP: [dbo].[z151BahayeTamamShodeForooshType1]
-- ===============================================
IF OBJECT_ID(N'dbo.z151BahayeTamamShodeForooshType1', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z151BahayeTamamShodeForooshType1] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z151BahayeTamamShodeForooshType1]

@lngDateFrom bigint,
@lngDateUntil bigint,
@SumBahayeTamamShode bigint output,
@MablagheEbtedayeDore bigint output,
@MablagheKharidTeyeDore bigint output,
@MablagheBargashtAzKharid bigint output,
@MablaghePayanDore bigint 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 #tmpGardesheKala
		(
			CodeKala bigint,
			CodeGroup bigint,
			CodeAnbar bigint,
			NameGroup nvarchar(100) collate Persian_100_CI_AS,
			NameKala nvarchar(100) collate Persian_100_CI_AS,
			NameAnbar nvarchar(100) collate Persian_100_CI_AS,
			TedadDarKarton bigint,

			MablagheEbteda bigint,
			TedadeEbteda bigint,
			TedadKartonEbteda nvarchar(100) collate Persian_100_CI_AS,

			MablagheKharid bigint,
			TedadeKharid bigint,
			TedadKartonKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheBargashtAzKharid bigint,
			TedadeBargashtAzKharid bigint,
			TedadKartonBargashtAzKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheKhalesKharid bigint,
			TedadeKhalesKharid bigint,
			TedadKartonKhalesKharid nvarchar(100) collate Persian_100_CI_AS,

			MablagheForoosh bigint,
			TedadeForoosh bigint,
			TedadeKartonForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablagheBargashtAzForoosh bigint,
			TedadeBargashtAzForoosh bigint,
			TedadeKartonBargashtAzForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablagheKhalesForoosh bigint,
			TedadeKhalesForoosh bigint,
			TedadKartonKhalesForoosh nvarchar(100) collate Persian_100_CI_AS,

			MablaghePayan bigint,
			TedadePayan bigint,
			TedadeKartonPayan nvarchar(100) collate Persian_100_CI_AS,

			BahayeTamamShodeForoosh bigint,
			SoodeKala bigint
		)

		delete #tmpGardesheKala
		insert into #tmpGardesheKala
			(CodeKala,CodeGroup,NameKala,TedadDarKarton)
			Select  fldCodeKala,fldCodeGroup,fldNameKala,fldTedadJoz 
				from  tblKala

		--update #tmpGardesheKala set TedadeEbteda=Sum(tblRizeKharid.fldTedadeJoz) from tblRizeKharid where #tmpGardesheKala.CodeKala=tblRizeKharid.fldCodeKala group by tblRizeKharid.fldCodeKala

		update           #tmpGardesheKala
			set NameGroup = tblGroupKala.fldGroupName from tblGroupKala Where CodeGroup=tblGroupKala.fldGroupId

		--####ابتدای دوره####
		update           #tmpGardesheKala
			set tedadeEbteda=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='mojodi_ebteda_doreh'  group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala

		
		update #tmpGardesheKala 
			set MablagheEbteda=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldFeeKol) as Sum1 from tblRizekharid Where fldType='mojodi_ebteda_doreh'   group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 
			--mojodi_ebteda_doreh



		----کارتن و عدد
		--update #tmpGardesheKala Set TedadKartonEbteda=Convert(varchar,floor(tedadeEbteda / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeEbteda, TedadDarKarton) } ) 
		--	where TedadDarKarton>0
		--######################
		--######خرید#####
		update           #tmpGardesheKala
			set tedadekharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizekharid Where fldType='kharid'   group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set Mablaghekharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizekharid Where fldType='kharid'   group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		----کارتن و عدد
		--update #tmpGardesheKala Set TedadKartonkharid=Convert(varchar,floor(TedadeKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeKharid, TedadDarKarton) } ) 
		--	where TedadDarKarton>0
		--#######################
		--######برگشت از خرید#####
		update           #tmpGardesheKala
			set tedadeBargashtAzkharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeBargashtAzkharid Where fldType='bargashtazkharid'   group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheBargashtAzKharid=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeBargashtAzkharid Where fldType='bargashtazkharid'   group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		----کارتن و عدد
		--update #tmpGardesheKala Set TedadKartonBargashtAzkharid=Convert(varchar,floor(TedadeBargashtAzKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeBargashtAzKharid, TedadDarKarton) } ) 
		--	where TedadDarKarton>0
		--#######################

		--######فروش#####
		update           #tmpGardesheKala
			set TedadeForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeForoosh Where fldType='Foroosh'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeForoosh Where fldType='Foroosh'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		----کارتن و عدد
		--update #tmpGardesheKala Set TedadeKartonForoosh=Convert(varchar,floor(TedadeForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeForoosh, TedadDarKarton) } ) 
		--	where TedadDarKarton>0

	--######برگشت از فروش#####
		update           #tmpGardesheKala
			set TedadeBargashtAzForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldTedadJoz) as Sum1 from tblRizeBargashtAzForoosh Where fldType='bargashtazforoosh'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 

		
		update #tmpGardesheKala 
			set MablagheBargashtAzForoosh=tbl1.Sum1 from  (Select fldCodeKala,Sum(fldMablaghKhales) as Sum1 from tblRizeBargashtAzForoosh Where fldType='bargashtazforoosh'  and (fldDate between @lngDateFrom and @lngDateUntil ) group by fldCodeKala) as tbl1
			Where #tmpGardesheKala.CodeKala=tbl1.fldCodeKala 			

		----کارتن و عدد
		--update #tmpGardesheKala Set TedadeKartonForoosh=Convert(varchar,floor(TedadeForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadeForoosh, TedadDarKarton) } ) 
		--	where TedadDarKarton>0
		--#######################
		--#######################
		update           #tmpGardesheKala
			set TedadeEbteda=0 Where TedadeEbteda is null  
		update           #tmpGardesheKala
			set TedadeKharid=0 Where TedadeKharid is null
		update           #tmpGardesheKala
			set TedadeBargashtAzKharid=0 Where TedadeBargashtAzKharid is null
		update           #tmpGardesheKala
			set TedadeForoosh=0 Where TedadeForoosh is null
		update           #tmpGardesheKala
			set TedadeBargashtAzForoosh=0 Where TedadeBargashtAzForoosh is null
		update           #tmpGardesheKala
			set MablagheEbteda=0 Where MablagheEbteda is null
		update           #tmpGardesheKala
			set MablagheKharid=0 Where MablagheKharid is null
		update           #tmpGardesheKala
			set MablagheForoosh=0 Where MablagheForoosh is null
		update           #tmpGardesheKala
			set MablaghePayan=0 Where MablaghePayan is null
		update           #tmpGardesheKala
			set bahayetamamshodeforoosh=0 Where bahayetamamshodeforoosh is null
		update           #tmpGardesheKala
			set SoodeKala=0 Where SoodeKala is null
		update           #tmpGardesheKala
			set MablagheBargashtAzKharid=0 Where MablagheBargashtAzKharid is null


		--######خالص خرید#######
		update           #tmpGardesheKala
			set TedadeKhalesKharid=TedadeEbteda+TedadeKharid-TedadeBargashtAzKharid

			
		update #tmpGardesheKala Set TedadKartonKhalesKharid=Convert(varchar,floor(TedadeKhalesKharid / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalesKharid, TedadDarKarton) } ) 
			where TedadDarKarton>0

		update #tmpGardesheKala Set MablagheKhalesKharid=MablagheEbteda+MablagheKharid-MablagheBargashtAzKharid

		--######خالص فروش#######
		update           #tmpGardesheKala
			set TedadeKhalesForoosh=TedadeForoosh-TedadeBargashtAzForoosh
		update #tmpGardesheKala Set TedadKartonKhalesForoosh=Convert(varchar,floor(TedadeKhalesForoosh / TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(TedadeKhalesForoosh, TedadDarKarton) } ) 
			where TedadDarKarton>0

		update #tmpGardesheKala Set MablagheKhalesForoosh=MablagheForoosh-MablagheBargashtAzForoosh
		--######پایان دوره#####
		update           #tmpGardesheKala
			set tedadePayan=TedadeEbteda+TedadeKharid+TedadeBargashtAzForoosh-TedadeForoosh-TedadeBargashtAzKharid
		update #tmpGardesheKala
			set MablaghePayan=(MablagheEbteda+MablagheKharid)/(TedadeEbteda+TedadeKharid)*tedadePayan
			where TedadeEbteda+TedadeKharid>0
		----کارتن و عدد
		--update #tmpGardesheKala Set TedadeKartonPayan=Convert(varchar,floor(TedadePayan/ TedadDarKarton)) + '-' +  +  Convert(varchar, { fn MOD(tedadePayan, TedadDarKarton) } ) 
		--	where TedadDarKarton>0
		--#######################

		--####انتقال بین انبار و تولید کنترل شود#######

		update #tmpGardesheKala set BahayeTamamShodeForoosh=(MablagheKhalesKharid/TedadeKhalesKharid)*TedadeKhalesForoosh  from #tmpGardesheKala where TedadeKhalesKharid>0  
		update #tmpGardesheKala set Mablaghekharid=0
		update #tmpGardesheKala set MablaghePayan=0
		
		delete  #tmpGardesheKala where  TedadePayan<0 

		


		--update #tmpGardesheKala set BahayeTamamShodeForoosh=MablagheEbteda+MablagheKharid-MablagheBargashtAzKharid-MablaghePayan

		--select BahayeTamamShodeForoosh,MablagheEbteda,MablagheKharid,MablagheBargashtAzKharid,MablaghePayan from #tmpGardesheKala
		--select Sum(MablagheEbteda)   from #tmpGardesheKala
		--select BahayeTamamShodeForoosh from #tmpGardesheKala
		--update #tmpGardesheKala set SoodeKala=MablagheForoosh-BahayeTamamShodeForoosh
		set @MablagheEbtedayeDore=(Select SUM(MablagheEbteda) from #tmpGardesheKala )
		set @MablagheKharidTeyeDore=(Select SUM(MablagheKharid) from #tmpGardesheKala )
		set @MablagheBargashtAzKharid=(Select SUM(MablagheBargashtAzKharid) from #tmpGardesheKala )
		set @MablaghePayanDore=(Select SUM(MablaghePayan) from #tmpGardesheKala )

		update           #tmpGardesheKala
			set bahayetamamshodeforoosh=0 Where bahayetamamshodeforoosh is null

		set @SumBahayeTamamShode=(Select SUM(BahayeTamamShodeForoosh) from #tmpGardesheKala)

		--Select MablagheEbteda,MablagheKharid,MablaghePayan, SUM(BahayeTamamShodeForoosh) as SumBahayeTamamShodeForooshrafte from #tmpGardesheKala
		--Select ROW_NUMBER() OVER(ORDER BY CodeKala ) AS Row, CodeKala,NameGroup,NameKala,TedadDarKarton,TedadeEbteda,TedadKartonEbteda,MablagheEbteda,
		--	TedadeKharid,TedadKartonKharid,MablagheKharid,TedadeForoosh,TedadeKartonForoosh,MablagheForoosh,TedadePayan,TedadeKartonPayan,MablaghePayan,BahayeTamamShodeForoosh ,SoodeKala
		--from #tmpGardesheKala
	
END
GO

-- ===============================================
-- SP: [dbo].[z151ShowList_ReportAmalkardeVisitor]
-- ===============================================
IF OBJECT_ID(N'dbo.z151ShowList_ReportAmalkardeVisitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z151ShowList_ReportAmalkardeVisitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z151ShowList_ReportAmalkardeVisitor]

	@ListVisitor varchar(5000)=null,
	@DateAz varchar(50),
	@DateTa varchar(50)
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 


create table #TempShow(
fldCodeSuperVisor bigint,
fldNameSuperVisor NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeVisitor bigint,
fldNameVisitor NVarchar(100) COLLATE Persian_100_CI_AS,
fldTedadForooshJoz bigint,
fldTedadFactor bigint,
fldMablaghForoosh decimal,
fldTedadFactorBargasht bigint,
fldTedadBargashtiJoz bigint,
fldMablaghBargashti decimal,
fldTedadForooshKhalesJoz bigint,
fldMablaghForooshKhales decimal,
fldSumTedadeMoshtari bigint,
fldSumTakhfifeDaryaft decimal,
fldSumTakhfifeGhalam decimal
)

create table #TempSumForoosh(
fldCodeTafzili bigint,
fldMablaghForoosh decimal,
fldTedadJozForoosh bigint,
fldSumTakhfifeGhalam decimal
)

create table #TempSumBargashtAzForoosh(
fldCodeTafzili bigint,
fldMablaghBargasht decimal,
fldTedadJozBargasht bigint
)

create table #TempSumKhalesForoosh(
fldCodeTafzili bigint,
fldMablaghKhales decimal,
fldTedadJozKhales bigint,
fldSumTakhfifeGhalam decimal
)

	delete from #TempShow
	delete from #TempSumForoosh
	delete from #TempSumBargashtAzForoosh
	delete from #TempSumKhalesForoosh

	declare @CodeMoinTakhfifDaryaft nvarchar(10)

	execute CodeMoinHesab 'takhfifatedaryaft',@CodeMoinTakhfifDaryaft output

insert into #TempSumForoosh(fldCodeTafzili,fldMablaghForoosh,fldTedadJozForoosh,fldSumTakhfifeGhalam)
			(select fldCodeVasete,Sum(fldMablaghKhales),Sum(fldTedadJoz),sum(fldMablaghTakhfif) from tblRizeForoosh where fldDate between @DateAz and @DateTa  group by fldCodeVasete )

insert into #TempSumBargashtAzForoosh(fldCodeTafzili,fldMablaghBargasht,fldTedadJozBargasht)
			(select fldCodeVasete,Sum(fldMablaghKhales),Sum(fldTedadJoz) from tblRizeBargashtAzForoosh where fldDate between @DateAz and @DateTa  group by fldCodeVasete)

insert into #TempSumKhalesForoosh(fldCodeTafzili,fldMablaghKhales,fldTedadJozKhales)
			(select dbo.viewLoadVizitor.fldCodeTafzili,0,0 from dbo.viewLoadVizitor)

update R Set R.fldMablaghKhales=(#TempSumForoosh.fldMablaghForoosh)-(#TempSumBargashtAzForoosh.fldMablaghBargasht),
								R.fldTedadJozKhales=(#TempSumForoosh.fldTedadJozForoosh)-(#TempSumBargashtAzForoosh.fldTedadJozBargasht)
								from #TempSumKhalesForoosh as R 
								inner join #TempSumForoosh on R.fldCodeTafzili=#TempSumForoosh.fldCodeTafzili
								inner join #TempSumBargashtAzForoosh on R.fldCodeTafzili=#TempSumBargashtAzForoosh.fldCodeTafzili

--update R Set R.fldMablaghKhales=(#TempSumForoosh.fldMablaghForoosh),
--								R.fldTedadJozKhales=(#TempSumForoosh.fldTedadJozForoosh)
--								from #TempSumKhalesForoosh as R 
--								inner join #TempSumForoosh on R.fldCodeTafzili=#TempSumForoosh.fldCodeTafzili						
--								where R.fldMablaghKhales=0

	


insert into #TempShow(
fldCodeSuperVisor,
fldNameSuperVisor,
fldCodeVisitor,
fldNameVisitor,
fldTedadForooshJoz,
fldMablaghForoosh,
fldTedadBargashtiJoz ,
fldMablaghBargashti ,
fldTedadForooshKhalesJoz ,
fldMablaghForooshKhales,
fldSumTedadeMoshtari,
fldSumTakhfifeDaryaft,
fldSumTakhfifeGhalam)
	(select dbo.viewLoadVizitor.CodeSuperVisor,dbo.viewLoadVizitor.fldNameSuperVizor , #TempSumKhalesForoosh.fldCodeTafzili,dbo.viewLoadVizitor.fldSharheTafzili
	,0 as fldTedadJozForoosh
	,0 as fldMablaghForoosh
	,0 as fldTedadBargashtiJoz 
	,0 as fldMablaghBargashti 
	,0 as fldTedadJozKhales
	,0 as fldMablaghKhales	
	,0 as fldSumTedadeMoshtari	
	,0 as fldSumTakhfifeDaryaft
	,0 as fldSumTakhfifeGhalam
	from #TempSumKhalesForoosh inner join
	dbo.viewLoadVizitor on dbo.viewLoadVizitor.fldCodeTafzili=#TempSumKhalesForoosh.fldCodeTafzili 	
			)






update R Set R.fldMablaghForoosh=(#TempSumForoosh.fldMablaghForoosh),
			 R.fldTedadForooshJoz=(#TempSumForoosh.fldTedadJozForoosh)
								from #TempShow as R 
								inner join #TempSumForoosh on R.fldCodeVisitor=#TempSumForoosh.fldCodeTafzili						

update R Set R.fldSumTakhfifeGhalam=(#TempSumForoosh.fldSumTakhfifeGhalam)
								from #TempShow as R 
								inner join #TempSumForoosh on R.fldCodeVisitor=#TempSumForoosh.fldCodeTafzili	


update R Set R.fldMablaghBargashti=(#TempSumBargashtAzForoosh.fldMablaghBargasht),
			 R.fldTedadBargashtiJoz=(#TempSumBargashtAzForoosh.fldTedadJozBargasht)
								from #TempShow as R 
								inner join #TempSumBargashtAzForoosh on R.fldCodeVisitor=#TempSumBargashtAzForoosh.fldCodeTafzili		
								
update #TempShow set fldTedadFactor=0 where fldTedadFactor is null
update #TempShow set fldtedadfactorbargasht=0 where fldtedadfactorbargasht is null				

update R Set R.fldMablaghForooshKhales =(#TempSumKhalesForoosh.fldMablaghKhales),
			 R.fldTedadForooshKhalesJoz=(#TempSumKhalesForoosh.fldTedadJozKhales)
								from #TempShow as R 
								inner join #TempSumKhalesForoosh on R.fldCodeVisitor=#TempSumKhalesForoosh.fldCodeTafzili



update #TempShow Set #TempShow.fldSumTakhfifeDaryaft=tbl1.SumBed from  (select Sum(fldBedehkar) as SumBed,fldVasete from tblSodooreSanad Where fldMoinKamel=@CodeMoinTakhfifDaryaft and fldDate between @dateaz and @DateTa group by fldVasete) as tbl1
			where #TempShow.fldCodeVisitor=tbl1.fldVasete
								--from #TempShow as R 
								--inner join tbl1 on R.fldCodeVisitor=tbl1.fldCodeTafzili	

update #TempShow set fldSumTakhfifeDaryaft=0 where fldSumTakhfifeDaryaft is NULL
update #TempShow set fldMablaghForooshKhales=fldMablaghForoosh  where  fldMablaghForooshKhales=0

--update #TempShow  set fldMablaghForooshKhales=(fldMablaghForooshKhales-fldSumTakhfifeDaryaft)

--update R Set R.fldSumTedadeMoshtari =(#TempSumKhalesForoosh.fldCodeTafzili)
--								from #TempShow as R 
--								inner join #TempSumKhalesForoosh on R.fldCodeVisitor=#TempSumKhalesForoosh.fldCodeTafzili

update #TempShow  Set fldSumTedadeMoshtari=tbl2.sumTedadMoshtari from  (select fldCodeVasete,count(fldCodeTafsili) as sumTedadMoshtari from (select distinct fldCodeTafsili,fldCodeVasete  from tblRizeForoosh where fldDate between @dateaz and @DateTa and fldCodeVasete<>0) as tbl1 group by fldCodeVasete) as tbl2 
								where fldCodeVisitor=tbl2.fldCodeVasete


						--(select distinct fldCodeTafsili  from tblRizeForoosh ) as tbl1

		if @ListVisitor<>''
		      begin
		       declare @StrDeleteVisitor varchar(5000)
		        set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListVisitor + ''
					execute(@StrDeleteVisitor)
		      end

--update #TempShow set fldTedadFactor=tbl1.cnt from
--(SELECT       count( tblForoosh.fldShomareFactorForoosh) as cnt,fldCodeVasete
--FROM            tblForoosh INNER JOIN
--                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor where tblforoosh.fldDate between @DateAz and @DateTa group by fldCodeVasete) as tbl1
--						 where #TempShow.fldCodeVisitor=tbl1.fldCodeVasete	
update #TempShow set fldTedadFactor=tbl3.cnt from
(select count(fldShomareFactor) as cnt,fldCodeVasete from
(select distinct fldShomareFactor,fldCodeVasete from tblRizeForoosh where tblRizeForoosh.fldDate between @DateAz and @DateTa) tbl2
group by fldCodeVasete) as tbl3 where #TempShow.fldCodeVisitor=tbl3.fldCodeVasete	


update #TempShow set fldTedadFactorBargasht=tbl3.cnt from
(select count(fldShomareFactor) as cnt,fldCodeVasete from
(select distinct fldShomareFactor,fldCodeVasete from tblRizeBargashtazForoosh where tblRizeBargashtazForoosh.fldDate between @DateAz and @DateTa) tbl2
group by fldCodeVasete) as tbl3 where #TempShow.fldCodeVisitor=tbl3.fldCodeVasete	

--update #TempShow set fldTedadFactorBargasht=tbl1.cnt from
--(SELECT       count( tblBargashtAzForoosh.fldShomareFactorForoosh) as cnt,fldCodeVasete
--FROM            tblBargashtAzForoosh INNER JOIN
--                         tblRizeBargashtAzForoosh ON tblBargashtAzForoosh.fldShomareFactorForoosh = tblRizeBargashtAzForoosh.fldShomareFactor where tblBargashtAzForoosh.fldDate between @DateAz and @DateTa group by fldCodeVasete) as tbl1
--						 where #TempShow.fldCodeVisitor=tbl1.fldCodeVasete	
update #TempShow set fldTedadFactor=0 where fldTedadFactor is null
update #TempShow set fldtedadfactorbargasht=0 where fldtedadfactorbargasht is null


update #TempShow set fldTedadForooshKhalesJoz=fldTedadForooshJoz  where  fldTedadForooshKhalesJoz=0

SELECT  ROW_NUMBER() OVER(ORDER BY fldCodeVisitor) as fldRadif,fldCodeSuperVisor,fldNameSuperVisor,fldCodeVisitor,fldNameVisitor,fldTedadFactor,fldTedadForooshJoz,fldSumTedadeMoshtari,fldSumTakhfifeGhalam,fldMablaghForoosh,fldTedadFactorBargasht,fldSumTakhfifeDaryaft,fldTedadBargashtiJoz,fldMablaghBargashti,fldTedadForooshKhalesJoz,fldMablaghForooshKhales
FROM            #TempShow 

END
GO

-- ===============================================
-- SP: [dbo].[z152ShowList_ReportSarResidKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.z152ShowList_ReportSarResidKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z152ShowList_ReportSarResidKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z152ShowList_ReportSarResidKharid]

	@ListAshkhas varchar(5000)=null,
	@DateFactorAz varchar(50),
	@DateFactorTa varchar(50),
	@DateSarResidAz varchar(50),
	@DateSarResidTa varchar(50)
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 


create table #TempShow(
fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablaghKharid decimal,
fldDateShow  Nvarchar(20) collate Persian_100_CI_AS,
fldDate bigint,
fldDateSarResidShow  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSarResid bigint
)

create table #TempSumKharid(
fldShomareFactor bigint,
fldMablaghKharid decimal

)
	delete from #TempShow
	delete from #TempSumKharid

	insert into #TempSumKharid(fldShomareFactor,fldMablaghKharid)
	select fldShomareFactor,sum(fldMablaghKhales)as fldMablaghKharid from tblRizeKharid
	group by fldShomareFactor




	insert into #TempShow(fldShomareFactor,fldCodeTafzili,fldSharhTafzili,fldMablaghKharid,fldDateShow,fldDate,fldDateSarResidShow,fldDateSarResid)
	select distinct dbo.tblRizeKharid.fldShomareFactor
	,dbo.tblRizeKharid.fldCodeTafsili
	,dbo.tblTafzili.fldSharheTafzili,0,
	SUBSTRING(CONVERT(nvarchar, tblKharid.fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblKharid.fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblKharid.fldDate), 7, 2) AS fldDateShow,
							 dbo.tblKharid.fldDate,
	SUBSTRING(CONVERT(nvarchar, tblKharid.fldDateSarResid), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblKharid.fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblKharid.fldDateSarResid), 7, 2) AS fldDateSarResidShow,
							 dbo.tblKharid.fldDateSarResid
	 from dbo.tblRizeKharid inner join
		dbo.tblTafzili on dbo.tblRizeKharid.fldCodeTafsili=dbo.tblTafzili.fldCodeTafzili inner join
		dbo.tblKharid on dbo.tblRizeKharid.fldShomareFactor=dbo.tblKharid.fldShomareFactorKharid 
		where dbo.tblKharid.fldDate between @DateFactorAz and @DateFactorTa and
			  dbo.tblKharid.fldDateSarResid between @DateSarResidAz and @DateSarResidTa
		
		update R Set R.fldMablaghKharid=(#TempSumKharid.fldMablaghKharid)	
								from #TempShow as R 
								inner join #TempSumKharid on R.fldShomareFactor=#TempSumKharid.fldShomareFactor						

		if @ListAshkhas <>''
		      begin
		       declare @StrDeleteVisitor varchar(5000)
		        set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListAshkhas + ''
					execute(@StrDeleteVisitor)
		      end

	

SELECT  ROW_NUMBER() OVER(ORDER BY fldCodeTafzili) as fldRadif,fldShomareFactor,fldCodeTafzili,fldSharhTafzili,fldMablaghKharid,fldDateShow,fldDate,
fldDateSarResidShow,fldDateSarResid   
FROM  #TempShow  

END
GO

-- ===============================================
-- SP: [dbo].[z153ShowList_ReportAmalKardKarbar]
-- ===============================================
IF OBJECT_ID(N'dbo.z153ShowList_ReportAmalKardKarbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z153ShowList_ReportAmalKardKarbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z153ShowList_ReportAmalKardKarbar]

	@ListKarbaran varchar(5000)=null,
	@Listform varchar(5000)=null,
	@DateAz varchar(50),
	@DateTa varchar(50)
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 


create table #TempShow(

fldCodeKarbar bigint,
fldShomare bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameForm NVarchar(100) COLLATE Persian_100_CI_AS,
NoeAmaliat NVarchar(100) COLLATE Persian_100_CI_AS,
fldDateShow  Nvarchar(20) collate Persian_100_CI_AS,
fldDate bigint,
fldTime  Nvarchar(20) collate Persian_100_CI_AS,
fldSharh Nvarchar(100) collate Persian_100_CI_AS
)


	delete from #TempShow
update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')
insert into #TempShow(fldCodeKarbar,fldNameKarbar,fldNameForm,NoeAmaliat,fldShomare,fldDateShow,fldDate,fldTime,fldSharh)
select fldCodeKarbar,fldNameKarbar,fldNameForm,NoeAmaliat,fldShomare,
							SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDateShow,			
							 fldDate,fldTime,fldSharh from tblAmalkardekarbar
							 where fldDate between @DateAz and @DateTa
	

	update #TempShow set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update #TempShow set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')


	if @ListKarbaran <>''
   begin
		 declare @StrDeleteKarbaran varchar(5000)
	     set  @StrDeleteKarbaran='delete from #TempShow 
		 where '+ @ListKarbaran + ''
		execute(@StrDeleteKarbaran)
	end

	if @Listform <>''
		      begin
		       declare @StrDeleteForms varchar(5000)
		        set  @StrDeleteForms='delete from #TempShow 
		            where '+ @Listform + ''
					execute(@StrDeleteForms)
		      end

SELECT  ROW_NUMBER() OVER(ORDER BY fldCodeKarbar) as fldRadif, fldCodeKarbar ,fldNameKarbar,fldNameForm,NoeAmaliat,fldShomare,fldDateShow,fldDate,
fldTime,fldSharh    
FROM  #TempShow  

END
GO

-- ===============================================
-- SP: [dbo].[z154ShowList_Forms]
-- ===============================================
IF OBJECT_ID(N'dbo.z154ShowList_Forms', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z154ShowList_Forms] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z154ShowList_Forms]

	
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;

	select Distinct fldNameForm from tblAmalkardekarbar

END
GO

-- ===============================================
-- SP: [dbo].[z155ShowList_ReportPishfactor]
-- ===============================================
IF OBJECT_ID(N'dbo.z155ShowList_ReportPishfactor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z155ShowList_ReportPishfactor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z155ShowList_ReportPishfactor]
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@ListVisitor varchar(5000)=null,
	@DateFactorAz varchar(50),
	@DateFactorTa varchar(50),
	@DatePishFactorAz varchar(50),
	@DatePishFactorTa varchar(50),
	@MablaghAz decimal, 
	@MablaghTa decimal
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 
 create table #TempSumPishForoosh(
fldShomareFactor bigint,
fldMablaghForoosh decimal,
fldCodeAnbar bigint

)
 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)
 create table #TempListDateTimeSabtFactor(
fldShomareFactor bigint,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS
)
create table #TempListDateTimeSabtPishFactor(
fldShomareFactor bigint,
fldTimeSabtPishFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtPishFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS
)
 create table #TempListDateFactor(
fldShomareFactor bigint,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS
)
create table #TempListDatePishFactor(
fldShomareFactor bigint,
fldDatePishFactor  Nvarchar(20) collate Persian_100_CI_AS
)

create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDatePishFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldTimeSabtPishFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtPishFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeVisitor bigint,
fldNameVisitor NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
fldShomareFactorForoosh bigint,
fldLock nvarchar(5)
)

create table #tempPishFactor(
fldShomareFactorForoosh bigint,
fldShomarePishFactor bigint
)

	delete from #TempListDateTimeSabtFactor
	delete from #TempListDateTimeSabtPishFactor
	delete from #TempShow
	delete from #TempSumPishForoosh
	delete from #TempListCodeAnbar

update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizePishForoosh where fldRadif=1)

insert into #TempSumPishForoosh(fldShomareFactor,fldMablaghForoosh,fldCodeAnbar)
			(select tblRizePishForoosh.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizePishForoosh  group by fldShomareFactor )


insert into #TempListDateTimeSabtFactor(fldShomareFactor,fldTimeSabtFactor,fldDateSabtFactor)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblAmalkardekarbar where fldNameForm='فروش' and NoeAmaliat=N'جدید' and fldDate Between @DateFactorAz and @DateFactorTa)
			--select * from #TempListDateTimeFactor

insert into #TempListDateTimeSabtPishFactor(fldShomareFactor,fldTimeSabtPishFactor,fldDateSabtPishFactor,fldNameKarbar)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldNameKarbar from tblAmalkardekarbar where fldNameForm=N'پیش فاکتور' and NoeAmaliat=N'جدید' and fldDate Between @DatePishFactorAz and @DateFactorTa)

insert into #TempListDateFactor(fldShomareFactor,fldDateFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizeForoosh)
			--select * from tblRizeForoosh

insert into #TempListDatePishFactor(fldShomareFactor,fldDatePishFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizePishForoosh)
			
			--select * from #TempListDateTimePishFactor
			--select * from tblAmalkardekarbar
update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumPishForoosh as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldDatePishFactor,fldTimeSabtFactor,fldTimeSabtPishFactor,fldDateSabtFactor,fldDateSabtPishFactor,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldNameKarbar,fldLock)
 select DISTINCT  tblRizePishForoosh.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,'' as fldDateFactor,'' as fldDatePishFactor,
						'' as fldTimeFacttor,'' as fldTimePishFacttor,'' as fldDateFacttor,'' as fldDatePishFacttor,
					tblRizePishForoosh.fldCodeVasete ,''as fldNameVisitor,#TempSumPishForoosh.fldCodeAnbar,'' as fldNameAnbar,'' as fldNameKarbar,tblPishForoosh.fldLock
							  
 from tblRizePishForoosh 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizePishForoosh.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumPishForoosh on #TempSumPishForoosh.fldShomareFactor=tblRizePishForoosh.fldShomareFactor
 inner join tblPishForoosh on #TempSumPishForoosh.fldShomareFactor=tblPishForoosh.fldShomareFactorForoosh




							--SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDateShow

	update R Set R.fldMablagh=(#TempSumPishForoosh.fldMablaghForoosh)
								from #TempShow as R 
								inner join #TempSumPishForoosh on R.fldShomareFactor=#TempSumPishForoosh.fldShomareFactor						
	update R Set R.fldNameVisitor=(viewLoadVizitor.fldSharheTafzili)
								from #TempShow as R 
								inner join viewLoadVizitor on R.fldCodeVisitor=viewLoadVizitor.fldCodeTafzili						

	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode
									
	update R Set R.fldTimeSabtFactor=(#TempListDateTimeSabtFactor.fldTimeSabtFactor),R.fldDateSabtFactor=(#TempListDateTimeSabtFactor.fldDateSabtFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor
	
	update R Set R.fldTimeSabtPishFactor=(#TempListDateTimeSabtPishFactor.fldTimeSabtPishFactor),R.fldDateSabtPishFactor=(#TempListDateTimeSabtPishFactor.fldDateSabtPishFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtPishFactor on R.fldShomareFactor=#TempListDateTimeSabtPishFactor.fldShomareFactor
	
	update R Set R.fldNameKarbar=(#TempListDateTimeSabtPishFactor.fldNameKarbar)
								from #TempShow as R 
								inner join #TempListDateTimeSabtPishFactor on R.fldShomareFactor=#TempListDateTimeSabtPishFactor.fldShomareFactor

	update R Set R.fldDateFactor=(#TempListDateFactor.fldDateFactor)
								from #TempShow as R 
								inner join #TempListDateFactor on R.fldShomareFactor=#TempListDateFactor.fldShomareFactor
	update R Set R.fldDatePishFactor=(#TempListDatePishFactor.fldDatePishFactor)
								from #TempShow as R 
								inner join #TempListDatePishFactor on R.fldShomareFactor=#TempListDatePishFactor.fldShomareFactor
	
	update #TempShow set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempShow.fldCodetafzili=tbl5.fldCodeTafzili

	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end

	if @ListVisitor <>''
		      begin
		       declare @StrDeleteVisitor varchar(5000)
		        set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListVisitor + ''
					execute(@StrDeleteVisitor)
		      end

	 if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end

	insert into #tempPishFactor
		(fldShomareFactorForoosh,fldShomarepishfactor)
	Select  fldShomareFactorForoosh,fldShomarepishfactor from tblForoosh Where (isnumeric(fldShomarePishFactor) = 1) and fldShomarePishFactor<>0


	update #TempShow set fldShomareFactorForoosh=#tempPishFactor.fldShomareFactorForoosh from #tempPishFactor Where #TempShow.fldShomareFactor=#tempPishFactor.fldShomarePishFactor
	
	--update #TempShow set fldShomarePishfactor =tblForoosh.fldShomarePishFactor from tblForoosh Where 
SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldDatePishFactor,fldTimeSabtFactor,fldTimeSabtPishFactor,fldDateSabtFactor,fldDateSabtPishFactor,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldNameKarbar,fldShomareTell,fldShomareFactorForoosh  
,fldLock FROM  #TempShow where 
fldMablagh between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

END
GO

-- ===============================================
-- SP: [dbo].[z155ShowList_ReportPishfactor_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z155ShowList_ReportPishfactor_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z155ShowList_ReportPishfactor_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z155ShowList_ReportPishfactor_WithUserCode]
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@ListVisitor varchar(5000)=null,
	@ListFeeDynamic varchar(5000)=null,
	@DateFactorAz varchar(50),
	@DateFactorTa varchar(50),
	@DatePishFactorAz varchar(50),
	@DatePishFactorTa varchar(50),
	@MablaghAz decimal, 
	@MablaghTa decimal,
	@UserCode bigint
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 
 create table #TempSumPishForoosh(
fldShomareFactor bigint,
fldMablaghForoosh decimal,
fldCodeAnbar bigint

)
 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)
 create table #TempListDateTimeSabtFactor(
fldShomareFactor bigint,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS
)
create table #TempListDateTimeSabtPishFactor(
fldShomareFactor bigint,
fldTimeSabtPishFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtPishFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS
)
 create table #TempListDateFactor(
fldShomareFactor bigint,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS
)
create table #TempListDatePishFactor(
fldShomareFactor bigint,
fldDatePishFactor  Nvarchar(20) collate Persian_100_CI_AS
)

create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDatePishFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldTimeSabtPishFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtPishFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeVisitor bigint,
fldNameVisitor NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeFeeDynamic bigint,
fldNameFeeDynamic NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
fldShomareFactorForoosh bigint,
fldLock nvarchar(5)
)

create table #tempPishFactor(
fldShomareFactorForoosh bigint,
fldShomarePishFactor bigint
)

	delete from #TempListDateTimeSabtFactor
	delete from #TempListDateTimeSabtPishFactor
	delete from #TempShow
	delete from #TempSumPishForoosh
	delete from #TempListCodeAnbar

update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizePishForoosh where fldRadif=1)

insert into #TempSumPishForoosh(fldShomareFactor,fldMablaghForoosh,fldCodeAnbar)
			(select tblRizePishForoosh.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizePishForoosh  group by fldShomareFactor )


insert into #TempListDateTimeSabtFactor(fldShomareFactor,fldTimeSabtFactor,fldDateSabtFactor)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblAmalkardekarbar where fldNameForm='فروش' and NoeAmaliat=N'جدید' and fldDate Between @DateFactorAz and @DateFactorTa)
			--select * from #TempListDateTimeFactor

insert into #TempListDateTimeSabtPishFactor(fldShomareFactor,fldTimeSabtPishFactor,fldDateSabtPishFactor,fldNameKarbar)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldNameKarbar from tblAmalkardekarbar where fldNameForm=N'پیش فاکتور' and NoeAmaliat=N'جدید' and fldDate Between @DatePishFactorAz and @DateFactorTa)

insert into #TempListDateFactor(fldShomareFactor,fldDateFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizeForoosh)
			--select * from tblRizeForoosh

insert into #TempListDatePishFactor(fldShomareFactor,fldDatePishFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizePishForoosh)
			
			--select * from #TempListDateTimePishFactor
			--select * from tblAmalkardekarbar
update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumPishForoosh as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldDatePishFactor,fldTimeSabtFactor,fldTimeSabtPishFactor,fldDateSabtFactor,fldDateSabtPishFactor,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldCodeFeeDynamic,fldNameFeeDynamic,fldNameKarbar,fldLock)
 select DISTINCT  tblRizePishForoosh.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,'' as fldDateFactor,'' as fldDatePishFactor,
						'' as fldTimeFacttor,'' as fldTimePishFacttor,'' as fldDateFacttor,'' as fldDatePishFacttor,
					tblRizePishForoosh.fldCodeVasete ,''as fldNameVisitor,#TempSumPishForoosh.fldCodeAnbar,'' as fldNameAnbar,tblPishForoosh.fldCodeFeeDynamic,'' as fldNameFeeDynamic,'' as fldNameKarbar,tblPishForoosh.fldLock
							  
 from tblRizePishForoosh 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizePishForoosh.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumPishForoosh on #TempSumPishForoosh.fldShomareFactor=tblRizePishForoosh.fldShomareFactor
 inner join tblPishForoosh on #TempSumPishForoosh.fldShomareFactor=tblPishForoosh.fldShomareFactorForoosh




							--SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDateShow

	update R Set R.fldMablagh=(#TempSumPishForoosh.fldMablaghForoosh)
								from #TempShow as R 
								inner join #TempSumPishForoosh on R.fldShomareFactor=#TempSumPishForoosh.fldShomareFactor						
	update R Set R.fldNameVisitor=(viewLoadVizitor.fldSharheTafzili)
								from #TempShow as R 
								inner join viewLoadVizitor on R.fldCodeVisitor=viewLoadVizitor.fldCodeTafzili						

	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode
									
	update R Set R.fldTimeSabtFactor=(#TempListDateTimeSabtFactor.fldTimeSabtFactor),R.fldDateSabtFactor=(#TempListDateTimeSabtFactor.fldDateSabtFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor
	
	update R Set R.fldTimeSabtPishFactor=(#TempListDateTimeSabtPishFactor.fldTimeSabtPishFactor),R.fldDateSabtPishFactor=(#TempListDateTimeSabtPishFactor.fldDateSabtPishFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtPishFactor on R.fldShomareFactor=#TempListDateTimeSabtPishFactor.fldShomareFactor
	
	update R Set R.fldNameKarbar=(#TempListDateTimeSabtPishFactor.fldNameKarbar)
								from #TempShow as R 
								inner join #TempListDateTimeSabtPishFactor on R.fldShomareFactor=#TempListDateTimeSabtPishFactor.fldShomareFactor

	update R Set R.fldDateFactor=(#TempListDateFactor.fldDateFactor)
								from #TempShow as R 
								inner join #TempListDateFactor on R.fldShomareFactor=#TempListDateFactor.fldShomareFactor
	update R Set R.fldDatePishFactor=(#TempListDatePishFactor.fldDatePishFactor)
								from #TempShow as R 
								inner join #TempListDatePishFactor on R.fldShomareFactor=#TempListDatePishFactor.fldShomareFactor
	
	update #TempShow set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempShow.fldCodetafzili=tbl5.fldCodeTafzili
	
	update R Set R.fldNameFeeDynamic=(tblSharheFeeDynamic.fldSharh)
								from #TempShow as R 
								inner join tblSharheFeeDynamic on R.fldCodeFeeDynamic=tblSharheFeeDynamic.fldCodeSharh
	
	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end

	if @ListVisitor <>''
		      begin
		       declare @StrDeleteVisitor varchar(5000)
		        set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListVisitor + ''
					execute(@StrDeleteVisitor)
		      end

	 if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end
			  	  	if @ListFeeDynamic <>''
		      begin
		       declare @StrDeleteFeeDynamic varchar(5000)
		        set  @StrDeleteFeeDynamic='delete from #TempShow 
		            where '+ @ListFeeDynamic + ''
					execute(@StrDeleteFeeDynamic)
		      end


	insert into #tempPishFactor
		(fldShomareFactorForoosh,fldShomarepishfactor)
	Select  fldShomareFactorForoosh,fldShomarepishfactor from tblForoosh Where (isnumeric(fldShomarePishFactor) = 1) and fldShomarePishFactor<>0


	update #TempShow set fldShomareFactorForoosh=#tempPishFactor.fldShomareFactorForoosh from #tempPishFactor Where #TempShow.fldShomareFactor=#tempPishFactor.fldShomarePishFactor

-- ########################################################	

	update #TempShow set fldDateFactor='' where isnumeric(fldShomareFactorForoosh)=0

declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 

-- ########################################################

	--update #TempShow set fldShomarePishfactor =tblForoosh.fldShomarePishFactor from tblForoosh Where 
SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldDatePishFactor,fldTimeSabtFactor,fldTimeSabtPishFactor,fldDateSabtFactor,fldDateSabtPishFactor,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldNameFeeDynamic,fldNameKarbar,fldShomareTell,fldShomareFactorForoosh  
,fldLock FROM  #TempShow where 
fldCodeTafzili in (select code from @accessCodes) and
fldMablagh between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

END
GO

-- ===============================================
-- SP: [dbo].[z156ReportMojoodieBetfkikAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.z156ReportMojoodieBetfkikAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z156ReportMojoodieBetfkikAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z156ReportMojoodieBetfkikAnbar]
  @userCode bigint,
  @MiangineKharid bigint output,
  @JameTedad bigint output,
  @lngSumTedadeKolSahih bigint output,
  @Order int,
  @Filter int,
  @ListCodeKala varchar(5000)=null,
  @ListCodeAnbar varchar(5000)=null,
  @ListGroupKala varchar(5000)=null,
  @DateTa bigint,
  @NoeFeeKharid int,
  @NoeAnbar nvarchar(20)
--@nn nvarchar(10)

as

IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin
 

create table #TempMojoodieAnbar(

fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldTedadeVorood decimal(18, 2),
fldTedadeKhorooj decimal(18, 2),
fldTedadeJoz decimal(18, 2), 
fldTedadeKol decimal(18, 2), 
fldTedadDarKarton decimal(18, 2),
fldCodeAnbar int,
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldNogheSefaresh decimal(18, 2),
fldFeeForoosh money,
fldLastFee money,
fldMianginFee money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldType nvarchar(20) COLLATE Persian_100_CI_AS
)


create table #TempShowMojoodi(

fldCodeKala bigint,
SumVorood decimal(18, 2),
SumVoroodT nvarchar(200),
SumKhorooj decimal(18, 2),
SumKhoroojT nvarchar(200),
SumMande decimal(18, 2),
Mande nvarchar(200),
fldTedadDarKarton decimal(18, 0),
fldTedadKartonadadSahih decimal(18, 2),
fldTedadDarKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldCodeAnbar int,
fldNameAnbar Nvarchar(200) COLLATE Persian_100_CI_AS, 
fldTedadVoroodKarton decimal(18, 2),
fldTedadVoroodKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldTedadKhoroojKarton decimal(18, 2),
fldTedadKhoroojKartonShow nvarchar(70) COLLATE Persian_100_CI_AS,
fldGroupName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeGroup bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldNogheSefaresh decimal(18, 2),
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
fldKharid bigint,
fldArzesheMojoodi bigint,
fldArzesheVorood bigint,
fldArzesheKhorooj bigint,
fldArzesheMande bigint,
fldFeeForoosh bigint
)


update tblRizeKharid set fldFeeKolBadAzTakhfif=fldFeeVahed1BadAzTakhfif*fldTedadJoz where  fldType='mojodi_ebteda_doreh'

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 Where flddate<=@DateTa


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' ,fldTedadJozNahaei, 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            tblRizeTolid where fldType='mahsool' and flddate<=@DateTa



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 Where flddate<=@DateTa


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 Where flddate<=@DateTa


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,fldTedadJozAvalie , - 1 , - 1 , fldCodeAnbar, 'NameAnbar' AS Expr6, - 1 AS Expr7, fldFeeJoz , 
                         0, - 1 AS Expr9, 'NameVahed1' AS Expr10, 'NameVahed2' AS Expr11,fldDate,fldType
FROM            tblRizeTolid where fldType='avalie' and flddate<=@DateTa


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 Where flddate<=@DateTa


update #TempMojoodieAnbar set fldFeeForoosh=tblKala.fldFeeForoosh from tblKala Where #TempMojoodieAnbar.fldCodeKala=tblKala.fldCodeKala

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)



if @NoeAnbar='amani'
	delete #TempMojoodieAnbar where fldCodeAnbar<2000
else
	delete #TempMojoodieAnbar where fldCodeAnbar>=2000


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


--فيلتر تا قبل از تاريخ 

if @Filter=5
	begin
		--Insert into #TempShowMojoodi
		--		(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid,fldFeeForoosh)
		--	SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, 0 AS SumTedadeKhorooj, SUM(fldTedadeVorood ) AS sumMande, 
		--							 fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0,fldFeeForoosh 
		--	FROM            #TempMojoodieAnbar where fldType='enteghal'
		--	GROUP BY fldCodeKala, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh

			Insert into #TempShowMojoodi
					(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala,fldCodeAnbar,fldNameAnbar, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid,fldFeeForoosh)
				SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
										 fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala,fldCodeAnbar,fldNameAnbar, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0,fldFeeForoosh
				FROM            #TempMojoodieAnbar where fldType='enteghal'
				GROUP BY fldCodeKala,fldCodeAnbar,fldNameAnbar, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh

	end
else
	begin
		Insert into #TempShowMojoodi
				(SumVorood,SumKhorooj,SumMande,fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala,fldCodeAnbar,fldNameAnbar, fldNogheSefaresh, fldNameVahed, fldNameVahed2,fldKharid,fldFeeForoosh)
			SELECT        SUM(fldTedadeVorood) AS SumTedadeVorood, SUM(fldTedadeKhorooj) AS SumTedadeKhorooj, SUM(fldTedadeVorood - fldTedadeKhorooj) AS sumMande, 
									 fldTedadDarKarton, fldGroupName, fldCodeGroup, fldCodeKala, fldNameKala,fldCodeAnbar,fldNameAnbar, fldNogheSefaresh, fldNameVahed, fldNameVahed2,0,fldFeeForoosh
			FROM            #TempMojoodieAnbar
			GROUP BY fldCodeKala,fldCodeAnbar,fldNameAnbar, fldGroupName, fldCodeGroup, fldNameKala, fldNogheSefaresh, fldNameVahed, fldNameVahed2, fldTedadDarKarton, fldTedadeKol,fldFeeForoosh

	end




update #TempShowMojoodi set Mande=SumMande,SumVoroodT=SumVorood,SumKhoroojT=SumKhorooj
update #TempShowMojoodi set Mande=LEFT(Convert(varchar,SumMande),len(Convert(varchar,SumMande))-3) where right(convert(varchar,SumMande),2)='00'
update #TempShowMojoodi set SumVoroodT=LEFT(Convert(varchar,SumVorood),len(Convert(varchar,SumVorood))-3) where right(convert(varchar,SumVorood),2)='00'
update #TempShowMojoodi set SumKhoroojT=LEFT(Convert(varchar,SumKhorooj),len(Convert(varchar,SumKhorooj))-3) where right(convert(varchar,SumKhorooj),2)='00'

--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(Convert(dec, SumMande), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadVoroodKartonShow=Convert(varchar,floor(SumVorood / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,SumVorood), fldTedadDarKarton) } ) + ' ' + fldNameVahed
	where fldTedadDarKarton>0

update #TempShowMojoodi Set fldTedadKhoroojKartonShow=Convert(varchar,floor(SumKhorooj / fldTedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(Convert(dec,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 @NoeFeeKharid=1 --ميانگين خريد
	if @Filter=5 
		begin
			update #TempShowMojoodi set fldKharid=tbl1.Miangin from
				(SELECT        ROUND(SUM(fldFeeKol) / SUM(fldTedadJoz), 0) AS Miangin, fldCodeKala
				FROM            tblRizeKharid
				where fldType<>'enteghal'
				GROUP BY fldCodeKala				
				) as tbl1
				where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala 
		end
	else
		begin		
			update #TempShowMojoodi set fldKharid=tbl1.Miangin from
				(SELECT        ROUND(SUM(fldFeeKol) / SUM(fldTedadJoz), 0) AS Miangin, fldCodeKala
				FROM            tblRizeKharid
				where fldType<>'enteghal'
				GROUP BY fldCodeKala
				having         SUM(fldTedadJoz)>0 
				) as tbl1
				where tbl1.fldCodeKala=#TempShowMojoodi.fldCodeKala 
		end
else --آخرين في خريد
	begin
	--update #TempShowMojoodi set fldKharid=ROUND((tblRizeKharid.fldFeeKol) / (tblRizeKharid.fldTedadJoz), 0) from
	--	tblRizeKharid where  tblRizeKharid.fldCodeKala=#TempShowMojoodi.fldCodeKala 
	
		DECLARE @t TABLE(
		UniqueID INT,
		fldCodeKala bigint,
		[Fee] decimal(18,0),
		fldDate BIGINT
		);

		insert into @t
			(fldCodeKala,[Fee],fldDate)
			Select fldCodeKala, ROUND((tblRizeKharid.fldFeeKolBadAzTakhfif) / (tblRizeKharid.fldTedadJoz), 0),fldDATE from tblRizeKharid where fldType<>'enteghal' and tblRizeKharid.fldTedadJoz>0


		update #TempShowMojoodi set fldKharid=tbl1.[Fee] from 
			(SELECT t.fldCodeKala,MAX(t.[Fee]) AS [Fee],t.fldDate
			FROM @t t
			INNER JOIN(
				SELECT MAX(fldDate) AS fldDate,fldCodeKala
				FROM @t t
				GROUP BY fldCodeKala
			) AS t2
			ON t.[fldDate] = t2.[fldDate] 
				AND t.[fldCodeKala] = t2.fldCodeKala
			GROUP BY 
				t.fldCodeKala,
				t.[fldDate])as tbl1
			Where #TempShowMojoodi.fldCodeKala=tbl1.fldCodeKala


	end
	



--پاک کردن گروه کالاهايي که در گزارش نيستن
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

if @Filter=5  --ارزش انتقال
	begin
		update #TempShowMojoodi set fldArzesheMojoodi=SumMande*fldKharid 
		update #TempShowMojoodi set fldArzesheVorood=SumVorood *fldKharid ,fldArzesheKhorooj=SumKhorooj * fldKharid 
	end
else
	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)
update #TempShowMojoodi set fldTedadKartonadadSahih=(SumMande/fldTedadDarKarton)   Where fldTedadDarKarton>0
update #TempShowMojoodi set fldTedadKartonadadSahih=0 Where isnumeric(fldTedadKartonadadSahih)=0
set @lngSumTedadeKolSahih=(Select Sum(fldTedadKartonadadSahih) from #TempShowMojoodi)


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,fldCodeAnbar,fldNameAnbar,fldNameVahed,fldNameVahed2,SumVoroodT as SumVorood,SumKhoroojT as SumKhorooj,Mande as SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid,fldArzesheMojoodi,fldFeeForoosh,fldArzesheVorood,fldArzesheKhorooj from #TempShowMojoodi '

--Select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumVorood,SumKhorooj,SumMande ,fldTedadDarKarton   ,fldTedadDarKartonShow ,
	--fldTedadVoroodKartonShow ,fldTedadKhoroojKartonShow ,fldCodeGroup,fldGroupName   ,fldNogheSefaresh,fldKharid ,@strorder
	--from #TempShowMojoodi

	
 -- Group Kala access
 Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA')
  if @value = 'True'
  Begin -- Limitation Active  
	-- Get All AccessKala
	declare @accesskala table(code bigint)
	insert into @accesskala 
	exec [ZSP_GetKalaAccesses] @userCode

	delete #TempShowMojoodi where fldCodeGroup not in (select code from @accesskala)
 end

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 Convert(dec,SumMande) desc'
else if @order=3 
	set @StrOrder=' order by Convert(dec,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

-- ===============================================
-- SP: [dbo].[z156TekrariRanandeAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.z156TekrariRanandeAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z156TekrariRanandeAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z156TekrariRanandeAnbar]

@fldCodeAnbar int,
@fldCodeRanande int,
@fldRadif int,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCount int
	if @IDType=0  --براي مقايسه براي حالت اضافه کردن رکورد
		begin
		 set @RowCount=(Select Count(fldCodeRanande) from tblEtesalRanandeBeAnbar  Where fldCodeRanande=@fldCodeRanande and fldCodeAnbar= @fldCodeAnbar and fldRadif<>@fldRadif)
		 set @flagOUt=@RowCount
		end
	else
		begin --براي مقايسه با غيرخودش در حالت ويرايش
		   set	@RowCount=(Select  Count(fldCodeRanande) from tblEtesalRanandeBeAnbar  Where fldCodeRanande=@fldCodeRanande and fldCodeAnbar= @fldCodeAnbar and fldRadif<>@fldRadif)
		   set @flagOUt=@RowCount
		end
end
GO

-- ===============================================
-- SP: [dbo].[z157ReportAmalkardeAnbardar]
-- ===============================================
IF OBJECT_ID(N'dbo.z157ReportAmalkardeAnbardar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z157ReportAmalkardeAnbardar] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z157ReportAmalkardeAnbardar] 
	@ListGroupAshkhas varchar(5000)=null ,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeAnbardar varchar(5000)=null,
	@CodeTafzili nvarchar(10),		
	@DataType varchar(40),
	@DateSarResidAz bigint,
	@DateSarResidTa bigint,
	@DateFactorAz bigint,
	@DateFactorTa bigint,
	@BedooneAnbardar bigint,
	@FlagSort Varchar(15),
	@SumFactorha bigint output,
	@SumMandeFactor bigint output,
	@SumMandeTasfieNashode bigint output,
	@SumKoleDaryafti bigint output
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie4(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheFactor][bigint],
	[fldMablagheMande][bigint],
	[fldMablagheBargashti][bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,	
	[fldDateSarResid][bigint],
	[fldDateFactor][bigint],
	[fldCodeAnbar][bigint],
	[ShomareDaryaft][bigint],
	[SharheTafzili][nvarchar](200) COLLATE Persian_100_CI_AS,
	[codeTafzili][nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldCodeGroupAshkhas][bigint],
	[NameGroup][nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldCodeAnbardar][bigint],
	[NameAnbardar][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Tell][nvarchar](50) COLLATE Persian_100_CI_AS,
	[Adress][nvarchar](200) COLLATE Persian_100_CI_AS

	)

	--insert into #tmpDaryaftTasfie4
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
		
	
	
	insert into #tmpDaryaftTasfie4
			(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldMablagheMande,fldCodeAnbar,fldSharh,fldDateSarResid,fldDateFactor)
			Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor, fldMablagheMandeFactor, fldCodeAnbar ,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
				from  dbo.tblTasfie INNER JOIN
				dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor 

		if @Codetafzili<>0 --يعني همه افراد
			delete #tmpDaryaftTasfie4 where fldCodeTafzili<>@CodeTafzili

	update #tmpDaryaftTasfie4
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor
	
	--بروزرساني جمع مبلغ برگشتي bm
	update #tmpDaryaftTasfie4
	set fldMablagheBargashti=tbl11.fldMablagheBargashti from
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as fldMablagheBargashti from tblRizeTasfie where fldShomareBargashtAzForoosh<>0 group by fldShomareFactor ) as tbl11
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl11.fldShomareFactor

		
	
	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor

	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	update   #tmpDaryaftTasfie4 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti - fldMablagheBargashti

	--بروزرساني کد تفصيلي
	update #tmpDaryaftTasfie4 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl3.fldShomareFactorForoosh

	--بروزرساني نام تفصيلي
	update #tmpDaryaftTasfie4 set SharheTafzili=tbl5.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl5
		where #tmpDaryaftTasfie4.codeTafzili=tbl5.fldCodeTafzili

	--بروزرساني کدگروه 
	update #tmpDaryaftTasfie4 set fldCodeGroupAshkhas=tbl6.fldCodeGroup from
		(Select fldCodeGroup,fldCodeTafzili from tblTafzili) as tbl6
		Where #tmpDaryaftTasfie4.fldCodeTafzili=tbl6.fldCodeTafzili
	
	--بروزرساني نام گروه
	update #tmpDaryaftTasfie4  set NameGroup=tbl6.fldGroupName from
		(Select fldGroupId,fldGroupName from tblGroupAshkhas) as tbl6
		where tbl6.fldGroupId=#tmpDaryaftTasfie4.fldCodeGroupAshkhas
	

	--بروزرساني کد راننده ها	
	--update #tmpDaryaftTasfie4  set fldCodeAnbardar = tbl7.fldCodeAnbardar from
	--	(SELECT        tblForoosh.fldShomareFactorForoosh , tblEtesalRanandeBeAnbar.fldCodeAnbardar
	--		FROM            tblForoosh  inner join
	--						 tblRizeForoosh ON tblRizeForoosh.fldShomareFactor=tblForoosh.fldShomareFactorForoosh INNER JOIN						  
	--						 tblEtesalRanandeBeAnbar ON tblRizeForoosh.fldCodeAnbar=tblEtesalRanandeBeAnbar.fldCodeAnbar
	--						 ) as tbl7
	--	where #tmpDaryaftTasfie4.fldShomareFactor=tbl7.fldShomareFactorForoosh 

	----بروزرساني نام راننده ها
	--update #tmpDaryaftTasfie4  set NameAnbardar =tbl8.fldSharheTafzili from
	--	(	SELECT        ID, fldSharheTafzili, fldCodeTafzili, fldOstan, fldCity, fldAddress
	--			FROM            tblTafzili
	--				Where fldCodeNoe='0' and fldNoePersonel='ranande') as tbl8
	--	where #tmpDaryaftTasfie4.fldCodeRanande=tbl8.fldCodeTafzili 
	
	--update #tmpDaryaftTasfie4 set fldCodeRanande=0 where NameRanande='' 
 if @BedooneAnbardar=0
 begin
	delete #tmpDaryaftTasfie4 where fldCodeAnbardar is  null	
 end
 else
 begin
	 delete #tmpDaryaftTasfie4 where fldCodeAnbardar is Not null
 end

		
	--بروزرساني تاريخ سررسيد bm
	update #tmpDaryaftTasfie4 set fldDateSarResid=tbl9.fldDateSarResid from
	(select fldDateSarResid,fldShomareFactor from tblTasfie) as tbl9
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl9.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateSarResid< @DateSarResidAz
		delete #tmpDaryaftTasfie4 Where fldDateSarResid> @DateSarResidTa
	--بروزرساني تاريخ فاکتور bm
	update #tmpDaryaftTasfie4 set fldDateFactor=tbl10.fldDate from
	(select fldDate,fldShomareFactor from tblRizeForoosh) as tbl10
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl10.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateFactor< @DateFactorAz
		delete #tmpDaryaftTasfie4 Where fldDateFactor> @DateFactorTa

	 if @ListCodeAshkhas <>''
		begin
			declare @StrDeleteAshkhas varchar(5000)
			set  @StrDeleteAshkhas='delete from #tmpDaryaftTasfie4 
				where fldCodeTafzili NOT IN ('+ @ListCodeAshkhas +')'
				execute(@StrDeleteAshkhas)
		end


		if @ListGroupAshkhas<>''
			begin
			declare @StrDeleteGroupAshkhas varchar(5000)
			set  @StrDeleteGroupAshkhas='delete from #tmpDaryaftTasfie4 
				where '+ @ListGroupAshkhas + ''
				execute(@StrDeleteGroupAshkhas)
			end


		if @ListCodeAnbardar <>''
			begin
					declare @StrDeleteAnbardar varchar(5000)
					set  @StrDeleteAnbardar='delete from #tmpDaryaftTasfie4 
						where '+ @ListCodeAnbardar + ''
						execute(@StrDeleteAnbardar)		
			end
		
		

	if @DataType='tasfienashode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande=(SumDaryafti+fldMablagheBargashti)
		end
	if @DataType='tasfieshode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande<>(SumDaryafti+fldMablagheBargashti)
		end
	--بروزرساني تلفن
	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #tmpDaryaftTasfie4  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin				
					update #tmpDaryaftTasfie4  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 #tmpDaryaftTasfie4  set Adress =tbl9.fldAddress from
		(Select fldAddress,fldCodeTafzili from tblTafzili) as tbl9			
		where #tmpDaryaftTasfie4.fldCodeTafzili=tbl9.fldCodeTafzili

	set @sumMandeTasfieNashode=(Select Sum(fldmandeTasfienashode) as SumMande from #tmpDaryaftTasfie4)
	if @sumMandeTasfieNashode is null
		set @sumMandeTasfieNashode=0

	set @SumFactorha=(Select Sum(fldMablagheFactor) as SumMande from #tmpDaryaftTasfie4)
	if @SumFactorha is null
		set @SumFactorha=0

	set @SumMandeFactor=(Select Sum(fldMablagheMande) as SumMande from #tmpDaryaftTasfie4)
	if @SumMandeFactor is null
		set @SumMandeFactor=0


	set @SumKoleDaryafti=(Select Sum(SumDaryafti) as SumMande from #tmpDaryaftTasfie4)
	if @SumKoleDaryafti is null
		set @SumKoleDaryafti=0

	


	if @FlagSort='date'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2)  as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameAnbardar,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0
				order by fldDateSarResid,fldShomareFactor
		
	if @FlagSort='factor'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameAnbardar,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by fldShomareFactor,fldDateSarResid
	
	if @FlagSort='bk'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameAnbardar,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0		
				order by fldmandeTasfienashode desc--,fldShomareFactor,fldDateSarResid

	if @FlagSort='kb'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
				NameAnbardar,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by Convert(bigint,fldmandeTasfienashode) asc--,fldShomareFactor,fldDateSarResid

	else if @FlagSort='nameshakhs'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
			substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameAnbardar,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by SharheTafzili asc,fldShomareFactor,fldDateSarResid

	else if @FlagSort='namegorooh'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameAnbardar,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameGroup asc,fldShomareFactor,fldDateSarResid

	else --@FlagSort='namevizitor'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameAnbardar,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameAnbardar 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 #tmpDaryaftTasfie4' + @order			


END
GO

-- ===============================================
-- SP: [dbo].[z157ReportAmalkardeanbardar_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z157ReportAmalkardeanbardar_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z157ReportAmalkardeanbardar_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z157ReportAmalkardeanbardar_WithUserCode] 
	@ListGroupAshkhas varchar(5000)=null ,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeanbardar varchar(5000)=null,
	@CodeTafzili nvarchar(10),		
	@DataType varchar(40),
	@DateSarResidAz bigint,
	@DateSarResidTa bigint,
	@DateFactorAz bigint,
	@DateFactorTa bigint,
	@Bedooneanbardar bigint,
	@FlagSort Varchar(15),
	@SumFactorha bigint output,
	@SumMandeFactor bigint output,
	@SumMandeTasfieNashode bigint output,
	@SumKoleDaryafti bigint output,
	@userCode bigint
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie4(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheFactor][bigint],
	[fldMablagheMande][bigint],
	[fldMablagheBargashti][bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,	
	[fldDateSarResid][bigint],
	[fldDateFactor][bigint],
	[fldCodeAnbar][bigint],
	[ShomareDaryaft][bigint],
	[SharheTafzili][nvarchar](200) COLLATE Persian_100_CI_AS,
	[codeTafzili][nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldCodeGroupAshkhas][bigint],
	[NameGroup][nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldCodeanbardar][bigint],
	[Nameanbardar][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Tell][nvarchar](50) COLLATE Persian_100_CI_AS,
	[Adress][nvarchar](200) COLLATE Persian_100_CI_AS

	)

	--insert into #tmpDaryaftTasfie4
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
		
	
	
	insert into #tmpDaryaftTasfie4
			(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldMablagheMande,fldCodeAnbar,fldSharh,fldDateSarResid,fldDateFactor)
			Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor, fldMablagheMandeFactor, fldCodeAnbar ,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
				from  dbo.tblTasfie INNER JOIN
				dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor 

		if @Codetafzili<>0 --يعني همه افراد
			delete #tmpDaryaftTasfie4 where fldCodeTafzili<>@CodeTafzili

	update #tmpDaryaftTasfie4
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor
	
	--بروزرساني جمع مبلغ برگشتي bm
	update #tmpDaryaftTasfie4
	set fldMablagheBargashti=tbl11.fldMablagheBargashti from
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as fldMablagheBargashti from tblRizeTasfie where fldShomareBargashtAzForoosh<>0 group by fldShomareFactor ) as tbl11
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl11.fldShomareFactor

		
	
	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor

	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	update   #tmpDaryaftTasfie4 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti - fldMablagheBargashti

	--بروزرساني کد تفصيلي
	update #tmpDaryaftTasfie4 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl3.fldShomareFactorForoosh

	--بروزرساني نام تفصيلي
	update #tmpDaryaftTasfie4 set SharheTafzili=tbl5.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl5
		where #tmpDaryaftTasfie4.codeTafzili=tbl5.fldCodeTafzili

	--بروزرساني کدگروه 
	update #tmpDaryaftTasfie4 set fldCodeGroupAshkhas=tbl6.fldCodeGroup from
		(Select fldCodeGroup,fldCodeTafzili from tblTafzili) as tbl6
		Where #tmpDaryaftTasfie4.fldCodeTafzili=tbl6.fldCodeTafzili
	
	--بروزرساني نام گروه
	update #tmpDaryaftTasfie4  set NameGroup=tbl6.fldGroupName from
		(Select fldGroupId,fldGroupName from tblGroupAshkhas) as tbl6
		where tbl6.fldGroupId=#tmpDaryaftTasfie4.fldCodeGroupAshkhas
	

	----بروزرساني کد راننده ها	
	--update #tmpDaryaftTasfie4  set fldCodeanbardar = tbl7.fldCodeanbardar from
	--	(SELECT        tblForoosh.fldShomareFactorForoosh , tblEtesalRanandeBeAnbar.fldCodeRanande
	--		FROM            tblForoosh  inner join
	--						 tblRizeForoosh ON tblRizeForoosh.fldShomareFactor=tblForoosh.fldShomareFactorForoosh INNER JOIN						  
	--						 tblEtesalRanandeBeAnbar ON tblRizeForoosh.fldCodeAnbar=tblEtesalRanandeBeAnbar.fldCodeAnbar
	--						 ) as tbl7
	--	where #tmpDaryaftTasfie4.fldShomareFactor=tbl7.fldShomareFactorForoosh 

	----بروزرساني نام راننده ها
	update #tmpDaryaftTasfie4  set  fldCodeanbardar  =tbl99.fldCodeAnbardar  from
	(SELECT t.fldShomareFactor,t.fldCodeAnbardar
		FROM tblHavaleGoroohi t
		INNER JOIN (
			SELECT fldShomareFactor, MAX(Id) AS MaxId
			FROM tblHavaleGoroohi
			GROUP BY fldShomareFactor
		) t2 ON t.fldShomareFactor = t2.fldShomareFactor AND t.Id = t2.MaxId) as tbl99
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl99.fldShomareFactor

update #tmpDaryaftTasfie4  set Nameanbardar =tbl8.fldSharheTafzili, fldCodeanbardar=tbl8.fldCodeTafzili from
		(	SELECT        ID, fldSharheTafzili, fldCodeTafzili, fldOstan, fldCity, fldAddress
				FROM            tblTafzili
					Where fldCodeNoe='0' ) as tbl8
		where #tmpDaryaftTasfie4.fldCodeanbardar=tbl8.fldCodeTafzili 
	
	update #tmpDaryaftTasfie4 set fldCodeanbardar=0 where Nameanbardar='' 
	--select * from #tmpDaryaftTasfie4
 if @Bedooneanbardar=0
 begin
	delete #tmpDaryaftTasfie4 where fldCodeanbardar is  null	
 end
 else
 begin
	 delete #tmpDaryaftTasfie4 where fldCodeanbardar is Not null
 end

		
	--بروزرساني تاريخ سررسيد bm
	update #tmpDaryaftTasfie4 set fldDateSarResid=tbl9.fldDateSarResid from
	(select fldDateSarResid,fldShomareFactor from tblTasfie) as tbl9
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl9.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateSarResid< @DateSarResidAz
		delete #tmpDaryaftTasfie4 Where fldDateSarResid> @DateSarResidTa
	--بروزرساني تاريخ فاکتور bm
	update #tmpDaryaftTasfie4 set fldDateFactor=tbl10.fldDate from
	(select fldDate,fldShomareFactor from tblRizeForoosh) as tbl10
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl10.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateFactor< @DateFactorAz
		delete #tmpDaryaftTasfie4 Where fldDateFactor> @DateFactorTa

	 if @ListCodeAshkhas <>''
		begin
			declare @StrDeleteAshkhas varchar(5000)
			set  @StrDeleteAshkhas='delete from #tmpDaryaftTasfie4 
				where fldCodeTafzili NOT IN ('+ @ListCodeAshkhas +')'
				execute(@StrDeleteAshkhas)
		end


		if @ListGroupAshkhas<>''
			begin
			declare @StrDeleteGroupAshkhas varchar(5000)
			set  @StrDeleteGroupAshkhas='delete from #tmpDaryaftTasfie4 
				where '+ @ListGroupAshkhas + ''
				execute(@StrDeleteGroupAshkhas)
			end


		if @ListCodeanbardar <>''
			begin
					declare @StrDeleteanbardar varchar(5000)
					set  @StrDeleteanbardar='delete from #tmpDaryaftTasfie4 
						where '+ @ListCodeanbardar + ''
						execute(@StrDeleteanbardar)		
			end
		
		

	if @DataType='tasfienashode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande=(SumDaryafti+fldMablagheBargashti)
		end
	if @DataType='tasfieshode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande<>(SumDaryafti+fldMablagheBargashti)
		end
	--بروزرساني تلفن
	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #tmpDaryaftTasfie4  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin				
					update #tmpDaryaftTasfie4  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 #tmpDaryaftTasfie4  set Adress =tbl9.fldAddress from
		(Select fldAddress,fldCodeTafzili from tblTafzili) as tbl9			
		where #tmpDaryaftTasfie4.fldCodeTafzili=tbl9.fldCodeTafzili

	set @sumMandeTasfieNashode=(Select Sum(fldmandeTasfienashode) as SumMande from #tmpDaryaftTasfie4)
	if @sumMandeTasfieNashode is null
		set @sumMandeTasfieNashode=0

	set @SumFactorha=(Select Sum(fldMablagheFactor) as SumMande from #tmpDaryaftTasfie4)
	if @SumFactorha is null
		set @SumFactorha=0

	set @SumMandeFactor=(Select Sum(fldMablagheMande) as SumMande from #tmpDaryaftTasfie4)
	if @SumMandeFactor is null
		set @SumMandeFactor=0


	set @SumKoleDaryafti=(Select Sum(SumDaryafti) as SumMande from #tmpDaryaftTasfie4)
	if @SumKoleDaryafti is null
		set @SumKoleDaryafti=0


-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################
delete from #tmpDaryaftTasfie4 where fldCodeTafzili not in (select code from @accessCodes)
-- ##########################################################
	


	if @FlagSort='date'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2)  as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			Nameanbardar,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0
				order by fldDateSarResid,fldShomareFactor
		
	if @FlagSort='factor'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			Nameanbardar,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by fldShomareFactor,fldDateSarResid
	
	if @FlagSort='bk'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			Nameanbardar,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0		
				order by fldmandeTasfienashode desc--,fldShomareFactor,fldDateSarResid

	if @FlagSort='kb'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
				Nameanbardar,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by Convert(bigint,fldmandeTasfienashode) asc--,fldShomareFactor,fldDateSarResid

	else if @FlagSort='nameshakhs'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
			substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		Nameanbardar,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by SharheTafzili asc,fldShomareFactor,fldDateSarResid

	else if @FlagSort='namegorooh'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		Nameanbardar,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameGroup asc,fldShomareFactor,fldDateSarResid

	else --@FlagSort='namevizitor'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		Nameanbardar,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by Nameanbardar 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 #tmpDaryaftTasfie4' + @order			


END
GO

-- ===============================================
-- SP: [dbo].[z157ReportAmalkardeRanande]
-- ===============================================
IF OBJECT_ID(N'dbo.z157ReportAmalkardeRanande', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z157ReportAmalkardeRanande] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z157ReportAmalkardeRanande] 
	@ListGroupAshkhas varchar(5000)=null ,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeRanande varchar(5000)=null,
	@CodeTafzili nvarchar(10),		
	@DataType varchar(40),
	@DateSarResidAz bigint,
	@DateSarResidTa bigint,
	@DateFactorAz bigint,
	@DateFactorTa bigint,
	@BedooneRanande bigint,
	@FlagSort Varchar(15),
	@SumFactorha bigint output,
	@SumMandeFactor bigint output,
	@SumMandeTasfieNashode bigint output,
	@SumKoleDaryafti bigint output
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie4(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheFactor][bigint],
	[fldMablagheMande][bigint],
	[fldMablagheBargashti][bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,	
	[fldDateSarResid][bigint],
	[fldDateFactor][bigint],
	[fldCodeAnbar][bigint],
	[ShomareDaryaft][bigint],
	[SharheTafzili][nvarchar](200) COLLATE Persian_100_CI_AS,
	[codeTafzili][nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldCodeGroupAshkhas][bigint],
	[NameGroup][nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldCodeRanande][bigint],
	[NameRanande][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Tell][nvarchar](50) COLLATE Persian_100_CI_AS,
	[Adress][nvarchar](200) COLLATE Persian_100_CI_AS

	)

	--insert into #tmpDaryaftTasfie4
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
		
	
	
	insert into #tmpDaryaftTasfie4
			(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldMablagheMande,fldCodeAnbar,fldSharh,fldDateSarResid,fldDateFactor)
			Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor, fldMablagheMandeFactor, fldCodeAnbar ,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
				from  dbo.tblTasfie INNER JOIN
				dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor 

		if @Codetafzili<>0 --يعني همه افراد
			delete #tmpDaryaftTasfie4 where fldCodeTafzili<>@CodeTafzili

	update #tmpDaryaftTasfie4
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor
	
	--بروزرساني جمع مبلغ برگشتي bm
	update #tmpDaryaftTasfie4
	set fldMablagheBargashti=tbl11.fldMablagheBargashti from
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as fldMablagheBargashti from tblRizeTasfie where fldShomareBargashtAzForoosh<>0 group by fldShomareFactor ) as tbl11
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl11.fldShomareFactor

		
	
	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor

	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	update   #tmpDaryaftTasfie4 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti - fldMablagheBargashti

	--بروزرساني کد تفصيلي
	update #tmpDaryaftTasfie4 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl3.fldShomareFactorForoosh

	--بروزرساني نام تفصيلي
	update #tmpDaryaftTasfie4 set SharheTafzili=tbl5.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl5
		where #tmpDaryaftTasfie4.codeTafzili=tbl5.fldCodeTafzili

	--بروزرساني کدگروه 
	update #tmpDaryaftTasfie4 set fldCodeGroupAshkhas=tbl6.fldCodeGroup from
		(Select fldCodeGroup,fldCodeTafzili from tblTafzili) as tbl6
		Where #tmpDaryaftTasfie4.fldCodeTafzili=tbl6.fldCodeTafzili
	
	--بروزرساني نام گروه
	update #tmpDaryaftTasfie4  set NameGroup=tbl6.fldGroupName from
		(Select fldGroupId,fldGroupName from tblGroupAshkhas) as tbl6
		where tbl6.fldGroupId=#tmpDaryaftTasfie4.fldCodeGroupAshkhas
	

	--بروزرساني کد راننده ها	
	update #tmpDaryaftTasfie4  set fldCodeRanande = tbl7.fldCodeRanande from
		(SELECT        tblForoosh.fldShomareFactorForoosh , tblEtesalRanandeBeAnbar.fldCodeRanande
			FROM            tblForoosh  inner join
							 tblRizeForoosh ON tblRizeForoosh.fldShomareFactor=tblForoosh.fldShomareFactorForoosh INNER JOIN						  
							 tblEtesalRanandeBeAnbar ON tblRizeForoosh.fldCodeAnbar=tblEtesalRanandeBeAnbar.fldCodeAnbar
							 ) as tbl7
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl7.fldShomareFactorForoosh 

	--بروزرساني نام راننده ها
	update #tmpDaryaftTasfie4  set NameRanande =tbl8.fldSharheTafzili from
		(	SELECT        ID, fldSharheTafzili, fldCodeTafzili, fldOstan, fldCity, fldAddress
				FROM            tblTafzili
					Where fldCodeNoe='0' and fldNoePersonel='ranande') as tbl8
		where #tmpDaryaftTasfie4.fldCodeRanande=tbl8.fldCodeTafzili 
	
	--update #tmpDaryaftTasfie4 set fldCodeRanande=0 where NameRanande='' 
 if @BedooneRanande=0
 begin
	delete #tmpDaryaftTasfie4 where fldCodeRanande is  null	
 end
 else
 begin
	 delete #tmpDaryaftTasfie4 where fldCodeRanande is Not null
 end

		
	--بروزرساني تاريخ سررسيد bm
	update #tmpDaryaftTasfie4 set fldDateSarResid=tbl9.fldDateSarResid from
	(select fldDateSarResid,fldShomareFactor from tblTasfie) as tbl9
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl9.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateSarResid< @DateSarResidAz
		delete #tmpDaryaftTasfie4 Where fldDateSarResid> @DateSarResidTa
	--بروزرساني تاريخ فاکتور bm
	update #tmpDaryaftTasfie4 set fldDateFactor=tbl10.fldDate from
	(select fldDate,fldShomareFactor from tblRizeForoosh) as tbl10
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl10.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateFactor< @DateFactorAz
		delete #tmpDaryaftTasfie4 Where fldDateFactor> @DateFactorTa

	 if @ListCodeAshkhas <>''
		begin
			declare @StrDeleteAshkhas varchar(5000)
			set  @StrDeleteAshkhas='delete from #tmpDaryaftTasfie4 
				where fldCodeTafzili NOT IN ('+ @ListCodeAshkhas +')'
				execute(@StrDeleteAshkhas)
		end


		if @ListGroupAshkhas<>''
			begin
			declare @StrDeleteGroupAshkhas varchar(5000)
			set  @StrDeleteGroupAshkhas='delete from #tmpDaryaftTasfie4 
				where '+ @ListGroupAshkhas + ''
				execute(@StrDeleteGroupAshkhas)
			end


		if @ListCodeRanande <>''
			begin
					declare @StrDeleteRanande varchar(5000)
					set  @StrDeleteRanande='delete from #tmpDaryaftTasfie4 
						where '+ @ListCodeRanande + ''
						execute(@StrDeleteRanande)		
			end
		
		

	if @DataType='tasfienashode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande=(SumDaryafti+fldMablagheBargashti)
		end
	if @DataType='tasfieshode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande<>(SumDaryafti+fldMablagheBargashti)
		end
	--بروزرساني تلفن
	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #tmpDaryaftTasfie4  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin				
					update #tmpDaryaftTasfie4  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 #tmpDaryaftTasfie4  set Adress =tbl9.fldAddress from
		(Select fldAddress,fldCodeTafzili from tblTafzili) as tbl9			
		where #tmpDaryaftTasfie4.fldCodeTafzili=tbl9.fldCodeTafzili

	set @sumMandeTasfieNashode=(Select Sum(fldmandeTasfienashode) as SumMande from #tmpDaryaftTasfie4)
	if @sumMandeTasfieNashode is null
		set @sumMandeTasfieNashode=0

	set @SumFactorha=(Select Sum(fldMablagheFactor) as SumMande from #tmpDaryaftTasfie4)
	if @SumFactorha is null
		set @SumFactorha=0

	set @SumMandeFactor=(Select Sum(fldMablagheMande) as SumMande from #tmpDaryaftTasfie4)
	if @SumMandeFactor is null
		set @SumMandeFactor=0


	set @SumKoleDaryafti=(Select Sum(SumDaryafti) as SumMande from #tmpDaryaftTasfie4)
	if @SumKoleDaryafti is null
		set @SumKoleDaryafti=0

	


	if @FlagSort='date'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2)  as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0
				order by fldDateSarResid,fldShomareFactor
		
	if @FlagSort='factor'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by fldShomareFactor,fldDateSarResid
	
	if @FlagSort='bk'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0		
				order by fldmandeTasfienashode desc--,fldShomareFactor,fldDateSarResid

	if @FlagSort='kb'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
				NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by Convert(bigint,fldmandeTasfienashode) asc--,fldShomareFactor,fldDateSarResid

	else if @FlagSort='nameshakhs'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
			substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by SharheTafzili asc,fldShomareFactor,fldDateSarResid

	else if @FlagSort='namegorooh'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameGroup asc,fldShomareFactor,fldDateSarResid

	else --@FlagSort='namevizitor'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameRanande 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 #tmpDaryaftTasfie4' + @order			


END
GO

-- ===============================================
-- SP: [dbo].[z157ReportAmalkardeRanande_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z157ReportAmalkardeRanande_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z157ReportAmalkardeRanande_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z157ReportAmalkardeRanande_WithUserCode] 
	@ListGroupAshkhas varchar(5000)=null ,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeRanande varchar(5000)=null,
	@CodeTafzili nvarchar(10),		
	@DataType varchar(40),
	@DateSarResidAz bigint,
	@DateSarResidTa bigint,
	@DateFactorAz bigint,
	@DateFactorTa bigint,
	@BedooneRanande bigint,
	@FlagSort Varchar(15),
	@SumFactorha bigint output,
	@SumMandeFactor bigint output,
	@SumMandeTasfieNashode bigint output,
	@SumKoleDaryafti bigint output,
	@userCode bigint
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie4(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheFactor][bigint],
	[fldMablagheMande][bigint],
	[fldMablagheBargashti][bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,	
	[fldDateSarResid][bigint],
	[fldDateFactor][bigint],
	[fldCodeAnbar][bigint],
	[ShomareDaryaft][bigint],
	[SharheTafzili][nvarchar](200) COLLATE Persian_100_CI_AS,
	[codeTafzili][nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldCodeGroupAshkhas][bigint],
	[NameGroup][nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldCodeRanande][bigint],
	[NameRanande][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Tell][nvarchar](50) COLLATE Persian_100_CI_AS,
	[Adress][nvarchar](200) COLLATE Persian_100_CI_AS

	)

	--insert into #tmpDaryaftTasfie4
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
		
	
	
	insert into #tmpDaryaftTasfie4
			(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldMablagheMande,fldCodeAnbar,fldSharh,fldDateSarResid,fldDateFactor)
			Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor, fldMablagheMandeFactor, fldCodeAnbar ,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
				from  dbo.tblTasfie INNER JOIN
				dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor 

		if @Codetafzili<>0 --يعني همه افراد
			delete #tmpDaryaftTasfie4 where fldCodeTafzili<>@CodeTafzili

	update #tmpDaryaftTasfie4
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor
	
	--بروزرساني جمع مبلغ برگشتي bm
	update #tmpDaryaftTasfie4
	set fldMablagheBargashti=tbl11.fldMablagheBargashti from
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as fldMablagheBargashti from tblRizeTasfie where fldShomareBargashtAzForoosh<>0 group by fldShomareFactor ) as tbl11
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl11.fldShomareFactor

		
	
	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor

	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	update   #tmpDaryaftTasfie4 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti - fldMablagheBargashti

	--بروزرساني کد تفصيلي
	update #tmpDaryaftTasfie4 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl3.fldShomareFactorForoosh

	--بروزرساني نام تفصيلي
	update #tmpDaryaftTasfie4 set SharheTafzili=tbl5.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl5
		where #tmpDaryaftTasfie4.codeTafzili=tbl5.fldCodeTafzili

	--بروزرساني کدگروه 
	update #tmpDaryaftTasfie4 set fldCodeGroupAshkhas=tbl6.fldCodeGroup from
		(Select fldCodeGroup,fldCodeTafzili from tblTafzili) as tbl6
		Where #tmpDaryaftTasfie4.fldCodeTafzili=tbl6.fldCodeTafzili
	
	--بروزرساني نام گروه
	update #tmpDaryaftTasfie4  set NameGroup=tbl6.fldGroupName from
		(Select fldGroupId,fldGroupName from tblGroupAshkhas) as tbl6
		where tbl6.fldGroupId=#tmpDaryaftTasfie4.fldCodeGroupAshkhas
	

	--بروزرساني کد راننده ها	
	update #tmpDaryaftTasfie4  set fldCodeRanande = tbl7.fldCodeRanande from
		(SELECT        tblForoosh.fldShomareFactorForoosh , tblEtesalRanandeBeAnbar.fldCodeRanande
			FROM            tblForoosh  inner join
							 tblRizeForoosh ON tblRizeForoosh.fldShomareFactor=tblForoosh.fldShomareFactorForoosh INNER JOIN						  
							 tblEtesalRanandeBeAnbar ON tblRizeForoosh.fldCodeAnbar=tblEtesalRanandeBeAnbar.fldCodeAnbar
							 ) as tbl7
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl7.fldShomareFactorForoosh 

	--بروزرساني نام راننده ها
	update #tmpDaryaftTasfie4  set NameRanande =tbl8.fldSharheTafzili from
		(	SELECT        ID, fldSharheTafzili, fldCodeTafzili, fldOstan, fldCity, fldAddress
				FROM            tblTafzili
					Where fldCodeNoe='0' and fldNoePersonel='ranande') as tbl8
		where #tmpDaryaftTasfie4.fldCodeRanande=tbl8.fldCodeTafzili 
	
	--update #tmpDaryaftTasfie4 set fldCodeRanande=0 where NameRanande='' 
 if @BedooneRanande=0
 begin
	delete #tmpDaryaftTasfie4 where fldCodeRanande is  null	
 end
 else
 begin
	 delete #tmpDaryaftTasfie4 where fldCodeRanande is Not null
 end

		
	--بروزرساني تاريخ سررسيد bm
	update #tmpDaryaftTasfie4 set fldDateSarResid=tbl9.fldDateSarResid from
	(select fldDateSarResid,fldShomareFactor from tblTasfie) as tbl9
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl9.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateSarResid< @DateSarResidAz
		delete #tmpDaryaftTasfie4 Where fldDateSarResid> @DateSarResidTa
	--بروزرساني تاريخ فاکتور bm
	update #tmpDaryaftTasfie4 set fldDateFactor=tbl10.fldDate from
	(select fldDate,fldShomareFactor from tblRizeForoosh) as tbl10
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl10.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateFactor< @DateFactorAz
		delete #tmpDaryaftTasfie4 Where fldDateFactor> @DateFactorTa

	 if @ListCodeAshkhas <>''
		begin
			declare @StrDeleteAshkhas varchar(5000)
			set  @StrDeleteAshkhas='delete from #tmpDaryaftTasfie4 
				where fldCodeTafzili NOT IN ('+ @ListCodeAshkhas +')'
				execute(@StrDeleteAshkhas)
		end


		if @ListGroupAshkhas<>''
			begin
			declare @StrDeleteGroupAshkhas varchar(5000)
			set  @StrDeleteGroupAshkhas='delete from #tmpDaryaftTasfie4 
				where '+ @ListGroupAshkhas + ''
				execute(@StrDeleteGroupAshkhas)
			end


		if @ListCodeRanande <>''
			begin
					declare @StrDeleteRanande varchar(5000)
					set  @StrDeleteRanande='delete from #tmpDaryaftTasfie4 
						where '+ @ListCodeRanande + ''
						execute(@StrDeleteRanande)		
			end
		
		

	if @DataType='tasfienashode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande=(SumDaryafti+fldMablagheBargashti)
		end
	if @DataType='tasfieshode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande<>(SumDaryafti+fldMablagheBargashti)
		end
	--بروزرساني تلفن
	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #tmpDaryaftTasfie4  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin				
					update #tmpDaryaftTasfie4  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 #tmpDaryaftTasfie4  set Adress =tbl9.fldAddress from
		(Select fldAddress,fldCodeTafzili from tblTafzili) as tbl9			
		where #tmpDaryaftTasfie4.fldCodeTafzili=tbl9.fldCodeTafzili

	set @sumMandeTasfieNashode=(Select Sum(fldmandeTasfienashode) as SumMande from #tmpDaryaftTasfie4)
	if @sumMandeTasfieNashode is null
		set @sumMandeTasfieNashode=0

	set @SumFactorha=(Select Sum(fldMablagheFactor) as SumMande from #tmpDaryaftTasfie4)
	if @SumFactorha is null
		set @SumFactorha=0

	set @SumMandeFactor=(Select Sum(fldMablagheMande) as SumMande from #tmpDaryaftTasfie4)
	if @SumMandeFactor is null
		set @SumMandeFactor=0


	set @SumKoleDaryafti=(Select Sum(SumDaryafti) as SumMande from #tmpDaryaftTasfie4)
	if @SumKoleDaryafti is null
		set @SumKoleDaryafti=0


-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################
delete from #tmpDaryaftTasfie4 where fldCodeTafzili not in (select code from @accessCodes)
-- ##########################################################
	


	if @FlagSort='date'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2)  as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0
				order by fldDateSarResid,fldShomareFactor
		
	if @FlagSort='factor'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by fldShomareFactor,fldDateSarResid
	
	if @FlagSort='bk'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0		
				order by fldmandeTasfienashode desc--,fldShomareFactor,fldDateSarResid

	if @FlagSort='kb'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
				NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by Convert(bigint,fldmandeTasfienashode) asc--,fldShomareFactor,fldDateSarResid

	else if @FlagSort='nameshakhs'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
			substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by SharheTafzili asc,fldShomareFactor,fldDateSarResid

	else if @FlagSort='namegorooh'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameGroup asc,fldShomareFactor,fldDateSarResid

	else --@FlagSort='namevizitor'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameRanande 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 #tmpDaryaftTasfie4' + @order			


END
GO

-- ===============================================
-- SP: [dbo].[z158ReportFactorBeTafkikRanande]
-- ===============================================
IF OBJECT_ID(N'dbo.z158ReportFactorBeTafkikRanande', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z158ReportFactorBeTafkikRanande] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z158ReportFactorBeTafkikRanande] 
	@ListGroupAshkhas varchar(5000)=null ,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeRanande varchar(5000)=null,
	@CodeTafzili nvarchar(10),		
	@DataType varchar(40),
	@DateSarResidAz bigint,
	@DateSarResidTa bigint,
	@DateFactorAz bigint,
	@DateFactorTa bigint,
	@BedooneRanande bigint,
	@FlagSort Varchar(15),
	@SumFactorha bigint output,
	@SumMandeFactor bigint output,
	@SumMandeTasfieNashode bigint output,
	@SumKoleDaryafti bigint output
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie4(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheFactor][bigint],
	[fldMablagheMande][bigint],
	[fldMablagheBargashti][bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,	
	[fldDateSarResid][bigint],
	[fldDateFactor][bigint],
	[fldCodeAnbar][bigint],
	[ShomareDaryaft][bigint],
	[SharheTafzili][nvarchar](200) COLLATE Persian_100_CI_AS,
	[codeTafzili][nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldCodeGroupAshkhas][bigint],
	[NameGroup][nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldCodeRanande][bigint],
	[NameRanande][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Tell][nvarchar](50) COLLATE Persian_100_CI_AS,
	[Adress][nvarchar](200) COLLATE Persian_100_CI_AS

	)

	--insert into #tmpDaryaftTasfie4
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
		
	
	
	insert into #tmpDaryaftTasfie4
			(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldMablagheMande,fldCodeAnbar,fldSharh,fldDateSarResid,fldDateFactor)
			Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor, fldMablagheMandeFactor, fldCodeAnbar ,fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
				from  dbo.tblTasfie INNER JOIN
				dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor 

		if @Codetafzili<>0 --يعني همه افراد
			delete #tmpDaryaftTasfie4 where fldCodeTafzili<>@CodeTafzili

	update #tmpDaryaftTasfie4
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor
	
	--بروزرساني جمع مبلغ برگشتي bm
	update #tmpDaryaftTasfie4
	set fldMablagheBargashti=tbl11.fldMablagheBargashti from
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as fldMablagheBargashti from tblRizeTasfie where fldShomareBargashtAzForoosh<>0 group by fldShomareFactor ) as tbl11
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl11.fldShomareFactor

		
	
	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor

	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	update   #tmpDaryaftTasfie4 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti - fldMablagheBargashti

	--بروزرساني کد تفصيلي
	update #tmpDaryaftTasfie4 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl3.fldShomareFactorForoosh

	--بروزرساني نام تفصيلي
	update #tmpDaryaftTasfie4 set SharheTafzili=tbl5.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl5
		where #tmpDaryaftTasfie4.codeTafzili=tbl5.fldCodeTafzili

	--بروزرساني کدگروه 
	update #tmpDaryaftTasfie4 set fldCodeGroupAshkhas=tbl6.fldCodeGroup from
		(Select fldCodeGroup,fldCodeTafzili from tblTafzili) as tbl6
		Where #tmpDaryaftTasfie4.fldCodeTafzili=tbl6.fldCodeTafzili
	
	--بروزرساني نام گروه
	update #tmpDaryaftTasfie4  set NameGroup=tbl6.fldGroupName from
		(Select fldGroupId,fldGroupName from tblGroupAshkhas) as tbl6
		where tbl6.fldGroupId=#tmpDaryaftTasfie4.fldCodeGroupAshkhas
	

	--بروزرساني کد راننده ها	
	update #tmpDaryaftTasfie4  set fldCodeRanande = tbl7.fldCodeRanande from
		(SELECT        tblForoosh.fldShomareFactorForoosh , tblHavaleGoroohi.fldCodeRanande
			FROM            tblForoosh   INNER JOIN						  
							 tblHavaleGoroohi ON tblForoosh.fldShomareFactorForoosh =tblHavaleGoroohi.fldShomareFactor  
												 
							 ) as tbl7
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl7.fldShomareFactorForoosh 

	--بروزرساني نام راننده ها
	update #tmpDaryaftTasfie4  set NameRanande =tbl8.fldSharheTafzili from
		(	SELECT        ID, fldSharheTafzili, fldCodeTafzili, fldOstan, fldCity, fldAddress
				FROM            tblTafzili
					Where fldCodeNoe='0' and fldNoePersonel='ranande') as tbl8
		where #tmpDaryaftTasfie4.fldCodeRanande=tbl8.fldCodeTafzili 
	
	--update #tmpDaryaftTasfie4 set fldCodeRanande=0 where NameRanande='' 
 if @BedooneRanande=0
 begin
	delete #tmpDaryaftTasfie4 where fldCodeRanande is  null	
 end
 else
 begin
	 delete #tmpDaryaftTasfie4 where fldCodeRanande is Not null
 end

		
	--بروزرساني تاريخ سررسيد bm
	update #tmpDaryaftTasfie4 set fldDateSarResid=tbl9.fldDateSarResid from
	(select fldDateSarResid,fldShomareFactor from tblTasfie) as tbl9
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl9.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateSarResid< @DateSarResidAz
		delete #tmpDaryaftTasfie4 Where fldDateSarResid> @DateSarResidTa
	--بروزرساني تاريخ فاکتور bm
	update #tmpDaryaftTasfie4 set fldDateFactor=tbl10.fldDate from
	(select fldDate,fldShomareFactor from tblRizeForoosh) as tbl10
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl10.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateFactor< @DateFactorAz
		delete #tmpDaryaftTasfie4 Where fldDateFactor> @DateFactorTa

	 if @ListCodeAshkhas <>''
		begin
			declare @StrDeleteAshkhas varchar(5000)
			set  @StrDeleteAshkhas='delete from #tmpDaryaftTasfie4 
				where fldCodeTafzili NOT IN ('+ @ListCodeAshkhas +')'
				execute(@StrDeleteAshkhas)
		end


		if @ListGroupAshkhas<>''
			begin
			declare @StrDeleteGroupAshkhas varchar(5000)
			set  @StrDeleteGroupAshkhas='delete from #tmpDaryaftTasfie4 
				where '+ @ListGroupAshkhas + ''
				execute(@StrDeleteGroupAshkhas)
			end


		if @ListCodeRanande <>''
			begin
					declare @StrDeleteRanande varchar(5000)
					set  @StrDeleteRanande='delete from #tmpDaryaftTasfie4 
						where '+ @ListCodeRanande + ''
						execute(@StrDeleteRanande)		
			end
		
		

	if @DataType='tasfienashode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande=(SumDaryafti+fldMablagheBargashti)
		end
	if @DataType='tasfieshode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande<>(SumDaryafti+fldMablagheBargashti)
		end
	--بروزرساني تلفن
	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #tmpDaryaftTasfie4  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin				
					update #tmpDaryaftTasfie4  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 #tmpDaryaftTasfie4  set Adress =tbl9.fldAddress from
		(Select fldAddress,fldCodeTafzili from tblTafzili) as tbl9			
		where #tmpDaryaftTasfie4.fldCodeTafzili=tbl9.fldCodeTafzili

	set @sumMandeTasfieNashode=(Select Sum(fldmandeTasfienashode) as SumMande from #tmpDaryaftTasfie4)
	if @sumMandeTasfieNashode is null
		set @sumMandeTasfieNashode=0

	set @SumFactorha=(Select Sum(fldMablagheFactor) as SumMande from #tmpDaryaftTasfie4)
	if @SumFactorha is null
		set @SumFactorha=0

	set @SumMandeFactor=(Select Sum(fldMablagheMande) as SumMande from #tmpDaryaftTasfie4)
	if @SumMandeFactor is null
		set @SumMandeFactor=0


	set @SumKoleDaryafti=(Select Sum(SumDaryafti) as SumMande from #tmpDaryaftTasfie4)
	if @SumKoleDaryafti is null
		set @SumKoleDaryafti=0

	


	if @FlagSort='date'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2)  as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0
				order by fldDateSarResid,fldShomareFactor
		
	if @FlagSort='factor'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by fldShomareFactor,fldDateSarResid
	
	if @FlagSort='bk'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0		
				order by fldmandeTasfienashode desc--,fldShomareFactor,fldDateSarResid

	if @FlagSort='kb'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
				NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by Convert(bigint,fldmandeTasfienashode) asc--,fldShomareFactor,fldDateSarResid

	else if @FlagSort='nameshakhs'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldmandeTasfienashode,
			substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by SharheTafzili asc,fldShomareFactor,fldDateSarResid

	else if @FlagSort='namegorooh'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameGroup asc,fldShomareFactor,fldDateSarResid

	else --@FlagSort='namevizitor'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,SumDaryafti,fldMablagheBargashti,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameRanande 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 #tmpDaryaftTasfie4' + @order			


END
GO

-- ===============================================
-- SP: [dbo].[z158ReportFactorBeTafkikRanande_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z158ReportFactorBeTafkikRanande_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z158ReportFactorBeTafkikRanande_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z158ReportFactorBeTafkikRanande_WithUserCode] 
	@ListGroupAshkhas varchar(5000)=null ,
	@ListCodeAshkhas varchar(5000)=null,
	@ListCodeRanande varchar(5000)=null,
	@CodeTafzili nvarchar(10),		
	@DataType varchar(40),
	@DateSarResidAz bigint,
	@DateSarResidTa bigint,
	@DateFactorAz bigint,
	@DateFactorTa bigint,
	@BedooneRanande bigint,
	@FlagSort Varchar(15),
	@SumFactorha bigint output,
	@SumMandeFactor bigint output,
	@SumMandeTasfieNashode bigint output,
	@SumKoleDaryafti bigint output,
	@userCode bigint
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie4(	
	[fldShomareFactor] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheFactor][bigint],
	[fldTedadeJozforoosh] decimal(18,2),
	[fldTedadeKartonForoosh] [bigint],
	[fldMablagheMande][bigint],
	[fldMablagheBargashti][bigint],
	[fldTedadeJozBargashtAzforoosh] decimal(18,2),
	[fldTedadeKartonBargashtAzForoosh] [bigint],
	[fldmandeTasfienashode] [bigint],
	[fldSharh][nvarchar](100) COLLATE Persian_100_CI_AS,	
	[fldDateSarResid][bigint],
	[fldDateFactor][bigint],
	[fldCodeAnbar][bigint],
	[ShomareDaryaft][bigint],
	[SharheTafzili][nvarchar](200) COLLATE Persian_100_CI_AS,
	[codeTafzili][nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldCodeGroupAshkhas][bigint],
	[NameGroup][nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldCodeRanande][bigint],
	[NameRanande][nvarchar](200) COLLATE Persian_100_CI_AS,
	[Tell][nvarchar](50) COLLATE Persian_100_CI_AS,
	[Adress][nvarchar](200) COLLATE Persian_100_CI_AS

	)

	--insert into #tmpDaryaftTasfie4
	--	(fldShomareFactor,SumDaryafti)
	--Select fldShomareFactor ,Sum(fldMablagh) as SumDaryafti from tblRizeTasfie   Group by fldShomareFactor
		
	
	
	insert into #tmpDaryaftTasfie4
			(fldShomareFactor,SumDaryafti,fldMablagheBargashti,fldCodeTafzili,fldMablagheFactor,fldMablagheMande,fldSharh,fldDateSarResid,fldDateFactor)
			Select distinct dbo.tblTasfie.fldShomareFactor,0,0,fldCodeTafzili,fldMablagheFactor, fldMablagheMandeFactor, fldSharh,fldDateSarResid, dbo.tblRizeForoosh.fldDate		
				from  dbo.tblTasfie INNER JOIN
				dbo.tblRizeForoosh  on dbo.tblTasfie.fldShomareFactor=dbo.tblRizeForoosh.fldShomareFactor 

		if @Codetafzili<>0 --يعني همه افراد
			delete #tmpDaryaftTasfie4 where fldCodeTafzili<>@CodeTafzili

	update #tmpDaryaftTasfie4
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfie where fldShomareDaryaft<>0 group by fldShomareFactor ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl1.fldShomareFactor
	
	--بروزرساني جمع مبلغ برگشتي bm
	update #tmpDaryaftTasfie4
	set fldMablagheBargashti=tbl11.fldMablagheBargashti from
		(Select fldShomareFactor, isnull(Sum(fldMablagh),0) as fldMablagheBargashti from tblRizeTasfie where fldShomareBargashtAzForoosh<>0 group by fldShomareFactor ) as tbl11
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl11.fldShomareFactor

		
	
	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	--	(Select fldShomareFactor, fldMablagh from tblRizeTasfie Where fldShomareDaryaft=@ShomareDaryaft) as tbl2
	--	where tbl2.fldShomareFactor=#tmpDaryaftTasfie4.fldShomareFactor

	--update #tmpDaryaftTasfie4 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	update   #tmpDaryaftTasfie4 set fldmandeTasfienashode=fldMablagheMande-SumDaryafti - fldMablagheBargashti

	--بروزرساني کد تفصيلي
	update #tmpDaryaftTasfie4 set codeTafzili=tbl3.fldCodeTafsili from
		(SELECT        tblForoosh.fldShomareFactorForoosh,tblRizeForoosh.fldCodeTafsili
			FROM            tblForoosh INNER JOIN
                         tblRizeForoosh ON tblForoosh.fldShomareFactorForoosh = tblRizeForoosh.fldShomareFactor) as tbl3
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl3.fldShomareFactorForoosh

	--بروزرساني نام تفصيلي
	update #tmpDaryaftTasfie4 set SharheTafzili=tbl5.fldSharheTafzili from
		(Select fldSharheTafzili,fldCodeTafzili from tblTafzili) as tbl5
		where #tmpDaryaftTasfie4.codeTafzili=tbl5.fldCodeTafzili

	--بروزرساني کدگروه 
	update #tmpDaryaftTasfie4 set fldCodeGroupAshkhas=tbl6.fldCodeGroup from
		(Select fldCodeGroup,fldCodeTafzili from tblTafzili) as tbl6
		Where #tmpDaryaftTasfie4.fldCodeTafzili=tbl6.fldCodeTafzili
	
	--بروزرساني نام گروه
	update #tmpDaryaftTasfie4  set NameGroup=tbl6.fldGroupName from
		(Select fldGroupId,fldGroupName from tblGroupAshkhas) as tbl6
		where tbl6.fldGroupId=#tmpDaryaftTasfie4.fldCodeGroupAshkhas
	

	--بروزرساني کد راننده ها	
	update #tmpDaryaftTasfie4  set fldCodeRanande = tbl7.fldCodeRanande from
		(SELECT        tblForoosh.fldShomareFactorForoosh , tblHavaleGoroohi.fldCodeRanande
			FROM            tblForoosh   INNER JOIN						  
							 tblHavaleGoroohi ON tblForoosh.fldShomareFactorForoosh =tblHavaleGoroohi.fldShomareFactor  
												 
							 ) as tbl7
		where #tmpDaryaftTasfie4.fldShomareFactor=tbl7.fldShomareFactorForoosh 

	--بروزرساني نام راننده ها
	update #tmpDaryaftTasfie4  set NameRanande =tbl8.fldSharheTafzili from
		(	SELECT        ID, fldSharheTafzili, fldCodeTafzili, fldOstan, fldCity, fldAddress
				FROM            tblTafzili
					Where fldCodeNoe='0' and fldNoePersonel='ranande') as tbl8
		where #tmpDaryaftTasfie4.fldCodeRanande=tbl8.fldCodeTafzili 
	
	--update #tmpDaryaftTasfie4 set fldCodeRanande=0 where NameRanande='' 
 if @BedooneRanande=0
 begin
	delete #tmpDaryaftTasfie4 where fldCodeRanande is  null	
 end
 else
 begin
	 delete #tmpDaryaftTasfie4 where fldCodeRanande is Not null
 end

		
	--بروزرساني تاريخ سررسيد bm
	update #tmpDaryaftTasfie4 set fldDateSarResid=tbl9.fldDateSarResid from
	(select fldDateSarResid,fldShomareFactor from tblTasfie) as tbl9
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl9.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateSarResid< @DateSarResidAz
		delete #tmpDaryaftTasfie4 Where fldDateSarResid> @DateSarResidTa
	--بروزرساني تاريخ فاکتور bm
	update #tmpDaryaftTasfie4 set fldDateFactor=tbl10.fldDate from
	(select fldDate,fldShomareFactor from tblRizeForoosh) as tbl10
	where #tmpDaryaftTasfie4.fldShomareFactor=tbl10.fldShomareFactor
		delete #tmpDaryaftTasfie4 Where fldDateFactor< @DateFactorAz
		delete #tmpDaryaftTasfie4 Where fldDateFactor> @DateFactorTa

	 if @ListCodeAshkhas <>''
		begin
			declare @StrDeleteAshkhas varchar(5000)
			set  @StrDeleteAshkhas='delete from #tmpDaryaftTasfie4 
				where fldCodeTafzili NOT IN ('+ @ListCodeAshkhas +')'
				execute(@StrDeleteAshkhas)
		end


		if @ListGroupAshkhas<>''
			begin
			declare @StrDeleteGroupAshkhas varchar(5000)
			set  @StrDeleteGroupAshkhas='delete from #tmpDaryaftTasfie4 
				where '+ @ListGroupAshkhas + ''
				execute(@StrDeleteGroupAshkhas)
			end


		if @ListCodeRanande <>''
			begin
					declare @StrDeleteRanande varchar(5000)
					set  @StrDeleteRanande='delete from #tmpDaryaftTasfie4 
						where '+ @ListCodeRanande + ''
						execute(@StrDeleteRanande)		
			end
		
		

	if @DataType='tasfienashode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande=(SumDaryafti+fldMablagheBargashti)
		end
	if @DataType='tasfieshode'
	begin
		delete from #tmpDaryaftTasfie4 where fldMablagheMande<>(SumDaryafti+fldMablagheBargashti)
		end
	--بروزرساني تلفن
	declare @EmpCodeTafzili nvarchar(10)
	declare EmpCursor Cursor For
		Select fldCodetafzili from #tmpDaryaftTasfie4  With (NoLock) 
			open EmpCursor
			fetch Next From EmpCursor into @EmpCodeTafzili
			While @@Fetch_Status = 0
				Begin				
					update #tmpDaryaftTasfie4  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 #tmpDaryaftTasfie4  set Adress =tbl9.fldAddress from
		(Select fldAddress,fldCodeTafzili from tblTafzili) as tbl9			
		where #tmpDaryaftTasfie4.fldCodeTafzili=tbl9.fldCodeTafzili

	set @sumMandeTasfieNashode=(Select Sum(fldmandeTasfienashode) as SumMande from #tmpDaryaftTasfie4)
	if @sumMandeTasfieNashode is null
		set @sumMandeTasfieNashode=0

	set @SumFactorha=(Select Sum(fldMablagheFactor) as SumMande from #tmpDaryaftTasfie4)
	if @SumFactorha is null
		set @SumFactorha=0

	set @SumMandeFactor=(Select Sum(fldMablagheMande) as SumMande from #tmpDaryaftTasfie4)
	if @SumMandeFactor is null
		set @SumMandeFactor=0


	set @SumKoleDaryafti=(Select Sum(SumDaryafti) as SumMande from #tmpDaryaftTasfie4)
	if @SumKoleDaryafti is null
		set @SumKoleDaryafti=0

-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################
delete from #tmpDaryaftTasfie4 
where fldCodeTafzili not in (select code from @accessCodes)
-- ##########################################################


--update #tmpDaryaftTasfie4 set fldTedadeJozforoosh=tblRizeForoosh.fldShomareFactor


UPDATE T
SET T.fldTedadeJozforoosh = S.TotalJoz
FROM #tmpDaryaftTasfie4 AS T
INNER JOIN (
    SELECT fldShomareFactor, SUM(fldTedadJoz) AS TotalJoz
    FROM tblRizeForoosh
    GROUP BY fldShomareFactor
) AS S
    ON T.fldShomareFactor = S.fldShomareFactor;

UPDATE T
SET T.fldTedadeJozforoosh = S.TotalJoz
FROM #tmpDaryaftTasfie4 AS T
INNER JOIN (
    SELECT fldShomareFactor, SUM(fldTedadJoz) AS TotalJoz
    FROM tblRizeForoosh
    GROUP BY fldShomareFactor
) AS S
    ON T.fldShomareFactor = S.fldShomareFactor;

--SELECT        LEFT(fldTedadCarton, CHARINDEX('-', fldTedadCarton) - 1) AS TedadAval,fldShomareFactor
--FROM            tblRizeForoosh
--WHERE        (fldTedadCarton <> '') and fldType='Foroosh'


UPDATE T
SET T.fldTedadeKartonForoosh = S.TotalAval
FROM #tmpDaryaftTasfie4 AS T
INNER JOIN (
    SELECT 
        fldShomareFactor,
        SUM( CAST(LEFT(fldTedadCarton, CHARINDEX('-', replace( fldTedadCarton,'.00','')) - 1) AS INT) ) AS TotalAval
    FROM tblRizeForoosh
    WHERE (fldTedadCarton <> '') AND fldType = 'Foroosh'
    GROUP BY fldShomareFactor
) AS S
    ON T.fldShomareFactor = S.fldShomareFactor;


--UPDATE T
--SET T.fldTedadeJozBargashtAzforoosh = S.TotalJoz
--FROM #tmpDaryaftTasfie4 AS T
--INNER JOIN (
--    SELECT 
--        R.fldShomareFactor,
--        SUM(R.fldTedadJoz) AS TotalJoz
--    FROM tblRizeBargashtAzForoosh AS R
--    WHERE R.fldShomareFactor IN (
--        SELECT Tsf.fldShomareBargashtAzForoosh
--        FROM tblRizeTasfie AS Tsf
--        WHERE Tsf.fldShomareBargashtAzForoosh <> 0
--          AND Tsf.fldShomareFactor IN (
--              SELECT tmp.fldShomareFactor FROM #tmpDaryaftTasfie4 AS tmp
--          )
--    )
--    GROUP BY R.fldShomareFactor
--) AS S
--ON T.fldShomareFactor = S.fldShomareFactor;

--select fldShomareFactor, fldTedadJoz from tblrizebargashtazforoosh where fldshomarefactor in
--(SELECT         fldShomareBargashtAzForoosh
--FROM            tblRizeTasfie
--WHERE         (fldShomareBargashtAzForoosh <> 0) and fldShomareFactor in (select fldShomareFactor from #tmpDaryaftTasfie4))

--SELECT        LEFT(fldTedadCarton, CHARINDEX('-', fldTedadCarton) - 1) AS TedadAval, fldTedadCarton
--FROM            tblRizeBargashtAzForoosh
--WHERE        (fldTedadCarton <> '') and fldshomarefactor in
--(SELECT         fldShomareBargashtAzForoosh
--FROM            tblRizeTasfie
--WHERE         (fldShomareBargashtAzForoosh <> 0) and fldShomareFactor in (select fldShomareFactor from #tmpDaryaftTasfie4))

--UPDATE T
--SET T.fldTedadeKartonBargashtAzForoosh = S.TotalAval
--FROM #tmpDaryaftTasfie4 AS T
--INNER JOIN (
--    SELECT 
--        R.fldShomareFactor,
--        SUM( CAST(LEFT(R.fldTedadCarton, CHARINDEX('-', R.fldTedadCarton) - 1) AS INT) ) AS TotalAval
--    FROM tblRizeBargashtAzForoosh AS R
--    WHERE (R.fldTedadCarton <> '')
--      AND R.fldShomareFactor IN (
--          SELECT Tsf.fldShomareBargashtAzForoosh
--          FROM tblRizeTasfie AS Tsf
--          WHERE Tsf.fldShomareBargashtAzForoosh <> 0
--            AND Tsf.fldShomareFactor IN (
--                SELECT tmp.fldShomareFactor 
--                FROM #tmpDaryaftTasfie4 AS tmp
--            )
--      )
--    GROUP BY R.fldShomareFactor
--) AS S
--ON T.fldShomareFactor = S.fldShomareFactor;

--SELECT        LEFT(fldTedadCarton, CHARINDEX('-', fldTedadCarton) - 1) AS TedadAval, fldTedadCarton
--FROM            tblRizeBargashtAzForoosh
--WHERE        (fldTedadCarton <> '')
--select * from tblRizeBargashtAzForoosh 

--update #tmpDaryaftTasfie4 set fldTedadeKartonBargashtAzForoosh= tbl2.sumKarton from 
--(select fldShomareFactor , sum(convert(dec,TedadAval)) as sumKarton from 
--(SELECT        LEFT(fldTedadCarton, CHARINDEX('-', fldTedadCarton) - 1) AS TedadAval, fldShomareFactor
--FROM            tblRizeBargashtAzForoosh
--WHERE    fldtype='bargashtazforoosh' and (fldTedadCarton <> '') and fldShomareFactor in (select fldShomareFactor from #tmpDaryaftTasfie4)) as tbl1
--group by fldShomareFactor) as tbl2
--where #tmpDaryaftTasfie4.fldShomareFactor=tbl2.fldShomareFactor



--SELECT        LEFT(fldTedadCarton, CHARINDEX('-', fldTedadCarton) - 1) AS TedadAval, fldShomareFactor
--FROM            tblRizeBargashtAzForoosh
--WHERE    fldtype='bargashtazforoosh' and (fldTedadCarton <> '') and fldShomareFactor
update #tmpDaryaftTasfie4 set fldTedadeJozBargashtAzforoosh= tbl4.sumKarton from 
(select shomareforoosh , sum(convert(dec,TedadAval)) as sumKarton from
(
SELECT       fldTedadJoz AS TedadAval, shomarebargasht,shomareforoosh from 

(
select fldTedadJoz,tblrizebargashtazforoosh.fldShomareFactor as shomarebargasht,tbl1.fldShomareFactor as shomareforoosh from tblrizebargashtazforoosh, 
(SELECT         fldShomareBargashtAzForoosh,fldShomareFactor
FROM            tblRizeTasfie
WHERE       (fldShomareBargashtAzForoosh <> 0) and fldShomareFactor in (select fldShomareFactor from #tmpDaryaftTasfie4)) as tbl1
where tblrizebargashtazforoosh.fldShomareFactor=tbl1.fldShomareBargashtAzForoosh  and fldtype='bargashtazforoosh'   and fldTedadCarton <> '' AND fldTedadCarton <> '0'

) as tbl2

) as tbl3
group by shomareforoosh) as tbl4
where #tmpDaryaftTasfie4.fldShomareFactor=shomareforoosh




update #tmpDaryaftTasfie4 set fldTedadeKartonBargashtAzForoosh= tbl4.sumKarton from 
(select shomareforoosh , sum(convert(dec,TedadAval)) as sumKarton from
(
SELECT        LEFT(fldTedadCarton, CHARINDEX('-', fldTedadCarton) - 1) AS TedadAval, shomarebargasht,shomareforoosh from 

(
select fldTedadCarton,tblrizebargashtazforoosh.fldShomareFactor as shomarebargasht,tbl1.fldShomareFactor as shomareforoosh from tblrizebargashtazforoosh, 
(SELECT         fldShomareBargashtAzForoosh,fldShomareFactor
FROM            tblRizeTasfie
WHERE       (fldShomareBargashtAzForoosh <> 0) and fldShomareFactor in (select fldShomareFactor from #tmpDaryaftTasfie4)) as tbl1
where tblrizebargashtazforoosh.fldShomareFactor=tbl1.fldShomareBargashtAzForoosh  and fldtype='bargashtazforoosh'   and fldTedadCarton <> '' AND fldTedadCarton <> '0'

) as tbl2

) as tbl3
group by shomareforoosh) as tbl4
where #tmpDaryaftTasfie4.fldShomareFactor=shomareforoosh


	if @FlagSort='date'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,fldTedadeJozforoosh,fldTedadeKartonForoosh,SumDaryafti,fldMablagheBargashti,fldTedadeJozBargashtAzforoosh,fldTedadeKartonBargashtAzForoosh,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2)  as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0
				order by fldDateSarResid,fldShomareFactor
		
	if @FlagSort='factor'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldMablagheMande,fldTedadeJozforoosh,fldTedadeKartonForoosh,SumDaryafti,fldMablagheBargashti,fldTedadeJozBargashtAzforoosh,fldTedadeKartonBargashtAzForoosh,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by fldShomareFactor,fldDateSarResid
	
	if @FlagSort='bk'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldTedadeJozforoosh,fldTedadeKartonForoosh,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldTedadeJozBargashtAzforoosh,fldTedadeKartonBargashtAzForoosh,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
			NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4	
				--where fldmandeTasfienashode>0		
				order by fldmandeTasfienashode desc--,fldShomareFactor,fldDateSarResid

	if @FlagSort='kb'
			Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldTedadeJozforoosh,fldTedadeKartonForoosh,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldTedadeJozBargashtAzforoosh,fldTedadeKartonBargashtAzForoosh,fldmandeTasfienashode,
				substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
				substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
				NameRanande,Tell,Adress,fldSharh
				from #tmpDaryaftTasfie4		
				--where fldmandeTasfienashode>0	
				order by Convert(bigint,fldmandeTasfienashode) asc--,fldShomareFactor,fldDateSarResid

	else if @FlagSort='nameshakhs'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldTedadeJozforoosh,fldTedadeKartonForoosh,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldTedadeJozBargashtAzforoosh,fldTedadeKartonBargashtAzForoosh,fldmandeTasfienashode,
			substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by SharheTafzili asc,fldShomareFactor,fldDateSarResid

	else if @FlagSort='namegorooh'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldTedadeJozforoosh,fldTedadeKartonForoosh,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldTedadeJozBargashtAzforoosh,fldTedadeKartonBargashtAzForoosh,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameGroup asc,fldShomareFactor,fldDateSarResid

	else --@FlagSort='namevizitor'
		Select codeTafzili,SharheTafzili,NameGroup,fldShomareFactor,fldMablagheFactor,fldTedadeJozforoosh,fldTedadeKartonForoosh,fldMablagheMande,SumDaryafti,fldMablagheBargashti,fldTedadeJozBargashtAzforoosh,fldTedadeKartonBargashtAzForoosh,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,	
			substring(convert(nvarchar(10),fldDateFactor),0,5) +'/' +substring(convert(nvarchar(10),fldDateFactor),5,2) + '/' + substring(convert(nvarchar(10),fldDateFactor),7,2)  as fldTarikhFactor,					
		NameRanande,Tell,Adress,fldSharh
			from #tmpDaryaftTasfie4		
			--where fldmandeTasfienashode>0	
			order by NameRanande 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 #tmpDaryaftTasfie4' + @order			


END
GO

-- ===============================================
-- SP: [dbo].[z160ShowList_ReportSefareshVisitor]
-- ===============================================
IF OBJECT_ID(N'dbo.z160ShowList_ReportSefareshVisitor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z160ShowList_ReportSefareshVisitor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z160ShowList_ReportSefareshVisitor]


	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@ListVisitor varchar(5000)=null,
	@DateAz varchar(50),
	@DateTa varchar(50),
	@MablaghAz decimal, 
	@MablaghTa decimal
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 
 create table #TempSumPishPishForoosh(
fldShomareFactor bigint,
fldMablaghForoosh decimal,
fldCodeAnbar bigint

)
 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)


create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDateShow  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeVisitor bigint,
fldNameVisitor NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldLock nvarchar(5)
)


	delete from #TempShow
	delete from #TempSumPishPishForoosh
	delete from #TempListCodeAnbar
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizePishPishForoosh where fldRadif=1)

insert into #TempSumPishPishForoosh(fldShomareFactor,fldMablaghForoosh,fldCodeAnbar)
			(select tblRizePishPishForoosh.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizePishPishForoosh where fldDate between @DateAz and @DateTa group by fldShomareFactor )

update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumPishPishForoosh as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateShow,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldDate,fldLock)
 select DISTINCT  tblRizePishPishForoosh.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,SUBSTRING(CONVERT(nvarchar,tblRizePishPishForoosh.fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblRizePishPishForoosh.fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblRizePishPishForoosh.fldDate), 7, 2) AS fldDateShow,
							 tblRizePishPishForoosh.fldCodeVasete ,''as fldNameVisitor,#TempSumPishPishForoosh.fldCodeAnbar,'' as fldNameAnbar,
							 tblRizePishPishForoosh.fldDate ,tblPishPishForoosh.fldLock
 from tblRizePishPishForoosh 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizePishPishForoosh.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumPishPishForoosh on #TempSumPishPishForoosh.fldShomareFactor=tblRizePishPishForoosh.fldShomareFactor
  inner join tblPishPishForoosh on tblPishPishForoosh.fldShomareFactorForoosh=tblRizePishPishForoosh.fldShomareFactor

	update R Set R.fldMablagh=(#TempSumPishPishForoosh.fldMablaghForoosh)
								from #TempShow as R 
								inner join #TempSumPishPishForoosh on R.fldShomareFactor=#TempSumPishPishForoosh.fldShomareFactor						
	update R Set R.fldNameVisitor=(viewLoadVizitor.fldSharheTafzili)
								from #TempShow as R 
								inner join viewLoadVizitor on R.fldCodeVisitor=viewLoadVizitor.fldCodeTafzili						

	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode	
	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end

	if @ListVisitor <>''
		      begin
		       declare @StrDeleteVisitor varchar(5000)
		        set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListVisitor + ''
					execute(@StrDeleteVisitor)
		      end
	

SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateShow,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldDate,fldLock   
FROM  #TempShow 
where fldMablagh between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)
END
GO

-- ===============================================
-- SP: [dbo].[z160ShowList_ReportSefareshVisitor_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z160ShowList_ReportSefareshVisitor_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z160ShowList_ReportSefareshVisitor_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z160ShowList_ReportSefareshVisitor_WithUserCode]


	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@ListVisitor varchar(5000)=null,
	@DateAz varchar(50),
	@DateTa varchar(50),
	@MablaghAz decimal, 
	@MablaghTa decimal,
	@userCode bigint,
	@type nvarchar(10)
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 
 create table #TempSumPishPishForoosh(
fldShomareFactor bigint,
fldMablaghForoosh decimal,
fldCodeAnbar bigint

)
 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)


create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(200) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDateShow  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeVisitor bigint,
fldNameVisitor NVarchar(200) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldDate bigint,
fldLock nvarchar(5)
)


	delete from #TempShow
	delete from #TempSumPishPishForoosh
	delete from #TempListCodeAnbar
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizePishPishForoosh where fldRadif=1)

insert into #TempSumPishPishForoosh(fldShomareFactor,fldMablaghForoosh,fldCodeAnbar)
			(select tblRizePishPishForoosh.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizePishPishForoosh where fldDate between @DateAz and @DateTa group by fldShomareFactor )

update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumPishPishForoosh as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateShow,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldDate,fldLock)
 select DISTINCT  tblRizePishPishForoosh.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,SUBSTRING(CONVERT(nvarchar,tblRizePishPishForoosh.fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, tblRizePishPishForoosh.fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, tblRizePishPishForoosh.fldDate), 7, 2) AS fldDateShow,
							 tblRizePishPishForoosh.fldCodeVasete ,''as fldNameVisitor,#TempSumPishPishForoosh.fldCodeAnbar,'' as fldNameAnbar,
							 tblRizePishPishForoosh.fldDate ,tblPishPishForoosh.fldLock
 from tblRizePishPishForoosh 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizePishPishForoosh.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumPishPishForoosh on #TempSumPishPishForoosh.fldShomareFactor=tblRizePishPishForoosh.fldShomareFactor
  inner join tblPishPishForoosh on tblPishPishForoosh.fldShomareFactorForoosh=tblRizePishPishForoosh.fldShomareFactor

	update R Set R.fldMablagh=(#TempSumPishPishForoosh.fldMablaghForoosh)
								from #TempShow as R 
								inner join #TempSumPishPishForoosh on R.fldShomareFactor=#TempSumPishPishForoosh.fldShomareFactor						
	update R Set R.fldNameVisitor=(viewLoadVizitor.fldSharheTafzili)
								from #TempShow as R 
								inner join viewLoadVizitor on R.fldCodeVisitor=viewLoadVizitor.fldCodeTafzili						

	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode	
	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end

	if @ListVisitor <>''
		      begin
		       declare @StrDeleteVisitor varchar(5000)
		        set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListVisitor + ''
					execute(@StrDeleteVisitor)
		      end

-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################	

if @type='tabdilshod'
	delete #TempShow where fldShomareFactor not in (Select fldShomarePishFactor from tblForoosh Where isnumeric(fldShomarePishFactor)=1 and fldShomarePishFactor<>0)
else if @type='tabdilnash'
	delete #TempShow where fldShomareFactor  in (Select fldShomarePishFactor from tblForoosh Where isnumeric(fldShomarePishFactor)=1 and fldShomarePishFactor<>0)


SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateShow,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldDate,fldLock   
FROM  #TempShow 
where 
fldCodeTafzili in (select code from @accessCodes) and
fldMablagh >= @MablaghAz and fldMablagh<= 999999999999
END
GO

-- ===============================================
-- SP: [dbo].[z161InsertSabteVamInfo]
-- ===============================================
IF OBJECT_ID(N'dbo.z161InsertSabteVamInfo', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z161InsertSabteVamInfo] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z161InsertSabteVamInfo]
						@fldTypemohasebe int,
						@fldShomareFactor bigint,
                        @fldCodeTafzili bigint,
                        @fldMablaghVam decimal,
                        @fldTedadAghsat bigint,
                        @fldShomareVam bigint,
                        @fldDarsadKarmozd decimal(18,1),
                        @fldDate bigint,
                        @fldTypeDorePardakht Nvarchar(50),
                        @fldDorePardakht Nvarchar(50),
                        @fldMablaghKarmozd decimal,
                        @fldMablaghVamBaKarmozd decimal,
                        @fldMablaghGhestBaKarmozd decimal,
                        @fldMablaghghestGhablAzKarmozd decimal,
                        @fldSharh Nvarchar(250),
                        @tblAghsat dtAghsat  readonly,
                        @strResult1 nvarchar(30) output,
						@strResult2 bigint output
as 


IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin


begin transaction AddRecord
		begin try

declare @MaxShomareVam bigint
declare @ShomareSanad bigint	
declare @SharhSanad nvarchar(50) 
declare @day nvarchar(50)  
declare @month nvarchar(50) 
declare @year nvarchar(50) 

Set @MaxShomareVam=(select Max(fldShomareVam) from tblVamInfo)
if isnumeric(@MaxShomareVam)=0
	set @MaxShomareVam=0

Set @year=SUBSTRING(CONVERT(nvarchar,@fldDate), 1, 4)
Set @month=SUBSTRING(CONVERT(nvarchar,@fldDate), 5, 2)
Set @day=SUBSTRING(CONVERT(nvarchar,@fldDate), 7, 2)
Set @SharhSanad=N'کارمزد اقساط وام شماره '+ Convert(varchar, @MaxShomareVam+1)

declare @Date6Ragham bigint,@TooleKol bigint,@Toolemoin bigint,@CodeMoinHesabhayeDaryaftani nvarchar(100),@CodeMoinKarmozdeVam nvarchar(100),@CodeKolkham nvarchar(10),@CodeMoinKham nvarchar(10)

set @Date6Ragham = @fldDate


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)


--INSERT INTO tblTest7
--                         ( fld2)
--VALUES        (@Date6Ragham)

execute insertSanadFirst @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,@fldCodeTafzili,NULL,@fldMablaghKarmozd,0,1,@Date6Ragham,@SharhSanad,@day,@month,@year,'vam',Null,@ShomareSanad output;


execute codemoinhesab 'karmozdevam' ,@CodeMoinKarmozdeVam output
set @CodeKolkham =substring(@CodeMoinKarmozdeVam, 1, @TooleKol)
set @CodeMoinKham =substring(@CodeMoinKarmozdeVam,@TooleKol+1,@Toolemoin)


execute insertSanadLast @CodeKolkham,@CodeMoinKham,@CodeMoinHesabhayeDaryaftani,NUll,NULL,0,@fldMablaghKarmozd,2,@Date6Ragham,@SharhSanad,@day,@month,@year,'vam',Null,@ShomareSanad;
	

insert into tblVamInfo(fldTypemohasebe,
						fldShomareVam,
						fldShomareFactor,
						fldShomareSanad,
						fldCodeTafzili,
						fldMablaghVam,
						fldTedadAghsat,
						fldDate,
						fldDarsadKarmozd,
						fldTypeDorePardakht,
						fldDorePardakht,
						fldMablaghKarmozd,
						 fldMablaghVamBaKarmozd,
                        fldMablaghghestGhablAzKarmozd,
                        fldMablaghGhestBaKarmozd,
						fldSharh)
Values(@fldTypemohasebe,
	   @MaxShomareVam+1,
	   @fldShomareFactor,
	   @ShomareSanad,
	   @fldCodeTafzili,
	   @fldMablaghVam,
	   @fldTedadAghsat,
	   @fldDate,
	   @fldDarsadKarmozd,
	   @fldTypeDorePardakht,
	   @fldDorePardakht,
	   @fldMablaghKarmozd,
       @fldMablaghVamBaKarmozd,
       @fldMablaghghestGhablAzKarmozd,
	   @fldMablaghGhestBaKarmozd,
	   @fldSharh
	   
)

		insert into tblDaftarcheAghsat(fldRadif,
									   fldShomareVam,
									   fldDateSarResid,									  
									   fldMablaghGhest
									  )
		(select fldRadif,
				@MaxShomareVam+1,		
				fldDateSarResid,		
				fldMablaghGhest		
				from @tblAghsat)

		set @strResult1= @MaxShomareVam+1

			
	commit transaction AddRecord;
		
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult1='error'
			    set @strResult2=(SELECT Error_Line() AS ErrorNumber)
				rollback transaction AddRecord;
			end
		end catch
		
end
GO

-- ===============================================
-- SP: [dbo].[z162ShowtblDaftarcheAghsat]
-- ===============================================
IF OBJECT_ID(N'dbo.z162ShowtblDaftarcheAghsat', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z162ShowtblDaftarcheAghsat] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z162ShowtblDaftarcheAghsat]					
                        @fldShomareVam bigint
                        
as 


IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin

select fldRadif,fldMablaghGhest,SUBSTRING(CONVERT(nvarchar,fldDateSarResid), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 7, 2) AS fldDateSarResid from tblDaftarcheAghsat
 where fldShomareVam=@fldShomareVam

		
end
GO

-- ===============================================
-- SP: [dbo].[z163ReportBetfkikGroupKala]
-- ===============================================
IF OBJECT_ID(N'dbo.z163ReportBetfkikGroupKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z163ReportBetfkikGroupKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z163ReportBetfkikGroupKala]
  @ListGroupKala varchar(5000)=null,
  @ListCodeAshkhas varchar(5000)=null,
  @ListCodeAnbar varchar(5000)=null,
  @DateAz bigint,
  @DateTa bigint


as

IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin
 

create table #TempBetfkikGroupKala(
Id bigint,
fldCodeTafzili bigint,
fldSharhTafzili nvarchar(150) COLLATE Persian_100_CI_AS,
fldCodeKala bigint,
fldSharhKala nvarchar(150) COLLATE Persian_100_CI_AS,
fldGroupKalaName nvarchar(150) COLLATE Persian_100_CI_AS,
fldCodeGroupKala bigint,
fldNameGroupAshkhas nvarchar(150) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldAnbarName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint,
fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
fldMablaghKhalesForoosh decimal,
fldDate bigint,
fldAddress nvarchar(1000) COLLATE Persian_100_CI_AS
)

--create table #TempShowBetfkikGroupKala(
--Id bigint,
--fldCodeTafzili bigint,
--fldSharhTafzili nvarchar(150) COLLATE Persian_100_CI_AS,
--fldCodeKala bigint,
--fldSharhKala nvarchar(150) COLLATE Persian_100_CI_AS,
--fldGroupKalaName nvarchar(150) COLLATE Persian_100_CI_AS,
--fldCodeGroupKala bigint,
--fldNameGroupAshkhas nvarchar(150) COLLATE Persian_100_CI_AS,
--fldCodeGroupAshkhas bigint,
--fldAnbarName nvarchar(50) COLLATE Persian_100_CI_AS,
--fldCodeAnbar bigint,
--fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
--fldMablaghKhalesForoosh decimal,
--fldDate bigint,
--fldAddress nvarchar(1000) COLLATE Persian_100_CI_AS
--)

delete #TempBetfkikGroupKala
--delete #TempShowBetfkikGroupKala

insert into #TempBetfkikGroupKala(Id,fldCodeTafzili
				,fldSharhTafzili
				,fldCodeKala
				,fldSharhKala
				,fldCodeGroupKala
				,fldGroupKalaName
				,fldCodeGroupAshkhas
				,fldNameGroupAshkhas
				,fldCodeAnbar
				,fldAnbarName
				,fldMablaghKhalesForoosh
				,fldDate
				,fldAddress)
select tblRizeForoosh.ID,tblRizeForoosh.fldCodeTafsili,tblTafzili.fldSharheTafzili,tblKala.fldCodeKala,fldSharhKala,'' as fldCodeGroupKala,'' as fldGroupKalaName,'' as fldCodeGroupAshkhas
,'' as fldNameGroupAshkhas,tblRizeForoosh.fldCodeAnbar,tblAnbar.fldNameAnbar,tblRizeForoosh.fldMablaghKhales,tblRizeForoosh.fldDate,tblTafzili.fldAddress
from tblRizeForoosh INNER JOIN
                         tblKala ON tblKala.fldCodeKala = tblRizeForoosh.fldCodeKala Inner Join
						 tblTafzili ON tblTafzili.fldCodeTafzili=tblRizeForoosh.fldCodeTafsili inner join
						 tblAnbar ON tblAnbar.fldCode=tblRizeForoosh.fldCodeAnbar 				
						where fldDate between @DateAz and @DateTa

						





update #TempBetfkikGroupKala set fldCodeGroupKala=tblGroupKala.fldGroupId, fldGroupKalaName=tblGroupKala.fldGroupName 
from tblKala inner join tblGroupKala ON tblGroupKala.fldGroupId=tblKala.fldCodeGroup
where tblKala.fldCodeKala=#TempBetfkikGroupKala.fldCodeKala	

update #TempBetfkikGroupKala set fldCodeGroupAshkhas=tblGroupAshkhas.fldGroupId,fldNameGroupAshkhas=tblGroupAshkhas.fldGroupName
from tblTafzili inner join tblGroupAshkhas ON tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
where tblTafzili.fldCodeTafzili=#TempBetfkikGroupKala.fldCodeTafzili	
	
	
update #TempBetfkikGroupKala set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempBetfkikGroupKala.fldCodetafzili=tbl5.fldCodeTafzili


--پاک کردن گروه کالاهایی که در گزارش نیستن
if @ListGroupKala<>''
	begin
		declare @StrDeleteGroupKala varchar(5000)
		set  @StrDeleteGroupKala='delete from #TempBetfkikGroupKala
		where '+ @ListGroupKala + ''
		execute(@StrDeleteGroupKala)
	end
if @ListCodeAshkhas<>''
	begin
		declare @StrDeleteGroupAshkhas varchar(5000)
		set  @StrDeleteGroupAshkhas='delete from #TempBetfkikGroupKala 
		where '+ @ListCodeAshkhas + ''
		execute(@StrDeleteGroupAshkhas)
	end
if @ListCodeAnbar<>''
	begin
		declare @StrDeleteAnbar varchar(5000)
		set  @StrDeleteAnbar='delete from #TempBetfkikGroupKala
		where '+ @ListCodeAnbar + ''
		execute(@StrDeleteAnbar)
	end
	



						 
--insert into #TempShowBetfkikGroupKala(fldMablaghKhalesForoosh,fldCodeTafzili,fldSharhTafzili
--,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldAddress)
--select sum(fldMablaghKhalesForoosh) as fldmSum,fldCodeTafzili,fldSharhTafzili
--,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldAddress from #TempBetfkikGroupKala
--Group By fldCodeTafzili,fldSharhTafzili
--,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldAddress


	
--update #TempShowBetfkikGroupKala set fldCodeTafzili=#TempBetfkikGroupKala.fldCodeTafzili
--	from #TempBetfkikGroupKala where #TempShowBetfkikGroupKala.fldSharhTafzili=#TempBetfkikGroupKala.fldSharhTafzili

--update #TempShowBetfkikGroupKala set fldCodeAnbar=#TempBetfkikGroupKala.fldCodeAnbar,fldAnbarName=#TempBetfkikGroupKala.fldAnbarName
--	from #TempBetfkikGroupKala where #TempShowBetfkikGroupKala.fldCodeTafzili=#TempBetfkikGroupKala.fldCodeTafzili

	
	

--update #TempShowBetfkikGroupKala set fldCodeGroupKala=#TempBetfkikGroupKala.fldCodeGroupKala, fldGroupKalaName=#TempBetfkikGroupKala.fldGroupKalaName 
--from #TempBetfkikGroupKala 
--where #TempBetfkikGroupKala.fldCodeTafzili=#TempBetfkikGroupKala.fldCodeTafzili	




 declare @StrOrder nvarchar(50)
 declare @Select nvarchar(500)



 Set @Select='select sum(fldMablaghKhalesForoosh) as fldMablaghKhalesForoosh,fldCodeTafzili,fldSharhTafzili
,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldShomareTell,fldAddress from #TempBetfkikGroupKala
Group By fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldShomareTell,fldAddress '

--Select fldCodeTafzili,fldSharhTafzili,fldCodeGroupKala,fldGroupKalaName
--,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldCodeAnbar,fldAnbarName,fldShomareTell,fldMablaghKhalesForoosh,fldAddress from #TempShowBetfkikGroupKala 

--if @Order=0 
--	set @StrOrder=' order by fldMablaghKhalesForoosh desc'
--else if @Order=1 	
--	set @StrOrder=' order by fldMablaghKhalesForoosh asc'

execute(@select)

	 

end
GO

-- ===============================================
-- SP: [dbo].[z163ReportBetfkikGroupKala_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z163ReportBetfkikGroupKala_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z163ReportBetfkikGroupKala_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z163ReportBetfkikGroupKala_WithUserCode]
  @ListGroupKala varchar(5000)=null,
  @ListCodeAshkhas varchar(5000)=null,
  @ListCodeAnbar varchar(5000)=null,
  @DateAz bigint,
  @DateTa bigint,
  @userCode bigint,
  @ListCodeVisitor varchar(5000)=null

as

IF 1=0 BEGIN
 SET FMTONLY OFF
END

begin
 

create table #TempBetfkikGroupKala(
Id bigint,
fldCodeTafzili bigint,
fldSharhTafzili nvarchar(150) COLLATE Persian_100_CI_AS,
fldCodeKala bigint,
fldSharhKala nvarchar(150) COLLATE Persian_100_CI_AS,
fldGroupKalaName nvarchar(150) COLLATE Persian_100_CI_AS,
fldCodeGroupKala bigint,
fldNameGroupAshkhas nvarchar(150) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldAnbarName nvarchar(50) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint,
fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
fldMablaghKhalesForoosh decimal,
fldtedad decimal(18,2),
fldDate bigint,
fldAddress nvarchar(1000) COLLATE Persian_100_CI_AS,
fldCodeVasete bigint,
fldNameVizitor nvarchar(1000) COLLATE Persian_100_CI_AS
)

--create table #TempShowBetfkikGroupKala(
--Id bigint,
--fldCodeTafzili bigint,
--fldSharhTafzili nvarchar(150) COLLATE Persian_100_CI_AS,
--fldCodeKala bigint,
--fldSharhKala nvarchar(150) COLLATE Persian_100_CI_AS,
--fldGroupKalaName nvarchar(150) COLLATE Persian_100_CI_AS,
--fldCodeGroupKala bigint,
--fldNameGroupAshkhas nvarchar(150) COLLATE Persian_100_CI_AS,
--fldCodeGroupAshkhas bigint,
--fldAnbarName nvarchar(50) COLLATE Persian_100_CI_AS,
--fldCodeAnbar bigint,
--fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
--fldMablaghKhalesForoosh decimal,
--fldDate bigint,
--fldAddress nvarchar(1000) COLLATE Persian_100_CI_AS
--)

delete #TempBetfkikGroupKala
--delete #TempShowBetfkikGroupKala

-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################


insert into #TempBetfkikGroupKala(Id,fldCodeTafzili
				,fldSharhTafzili
				,fldCodeKala
				,fldSharhKala
				,fldCodeGroupKala
				,fldGroupKalaName
				,fldCodeGroupAshkhas
				,fldNameGroupAshkhas
				,fldCodeAnbar
				,fldAnbarName
				,fldMablaghKhalesForoosh
				,fldtedad
				,fldDate
				,fldAddress
				,fldCodeVasete)
select tblRizeForoosh.ID,tblRizeForoosh.fldCodeTafsili,tblTafzili.fldSharheTafzili,tblKala.fldCodeKala,fldSharhKala,'' as fldCodeGroupKala,'' as fldGroupKalaName,'' as fldCodeGroupAshkhas
,'' as fldNameGroupAshkhas,tblRizeForoosh.fldCodeAnbar,tblAnbar.fldNameAnbar,tblRizeForoosh.fldMablaghKhales,tblRizeForoosh.fldTedadJoz, tblRizeForoosh.fldDate,tblTafzili.fldAddress,tblTafzili.fldVisitor
from tblRizeForoosh INNER JOIN
                         tblKala ON tblKala.fldCodeKala = tblRizeForoosh.fldCodeKala Inner Join
						 tblTafzili ON tblTafzili.fldCodeTafzili=tblRizeForoosh.fldCodeTafsili inner join
						 tblAnbar ON tblAnbar.fldCode=tblRizeForoosh.fldCodeAnbar 				
						where 
						fldCodeTafsili in (select code from @accessCodes) and
						fldDate between @DateAz and @DateTa



	insert into #TempBetfkikGroupKala(Id,fldCodeTafzili
				,fldSharhTafzili
				,fldCodeKala
				,fldSharhKala
				,fldCodeGroupKala
				,fldGroupKalaName
				,fldCodeGroupAshkhas
				,fldNameGroupAshkhas
				,fldCodeAnbar
				,fldAnbarName
				,fldMablaghKhalesForoosh
				,fldtedad
				,fldDate
				,fldAddress
				,fldCodeVasete)
select tblRizeBargashtAzForoosh.ID,tblRizeBargashtAzForoosh.fldCodeTafsili,tblTafzili.fldSharheTafzili,tblKala.fldCodeKala,fldSharhKala,'' as fldCodeGroupKala,'' as fldGroupKalaName,'' as fldCodeGroupAshkhas
,'' as fldNameGroupAshkhas,tblRizeBargashtAzForoosh.fldCodeAnbar,tblAnbar.fldNameAnbar,-1*tblRizeBargashtAzForoosh.fldMablaghKhales,tblRizeBargashtAzForoosh.fldTedadJoz, tblRizeBargashtAzForoosh.fldDate,tblTafzili.fldAddress,tbltafzili.fldVisitor
from tblRizeBargashtAzForoosh INNER JOIN
                         tblKala ON tblKala.fldCodeKala = tblRizeBargashtAzForoosh.fldCodeKala Inner Join
						 tblTafzili ON tblTafzili.fldCodeTafzili=tblRizeBargashtAzForoosh.fldCodeTafsili inner join
						 tblAnbar ON tblAnbar.fldCode=tblRizeBargashtAzForoosh.fldCodeAnbar 				
						where 
						fldCodeTafsili in (select code from @accessCodes) and
						fldDate between @DateAz and @DateTa					


update #TempBetfkikGroupKala set fldCodeVasete=0 where fldCodeVasete is NULL
if @ListCodeVisitor<>''
	begin
	declare @StrDeleteVisitor varchar(5000)
	set  @StrDeleteVisitor='delete from #TempBetfkikGroupKala 
		where '+ @ListCodeVisitor + ''
		execute(@StrDeleteVisitor)
	end



update #TempBetfkikGroupKala set fldCodeGroupKala=tblGroupKala.fldGroupId, fldGroupKalaName=tblGroupKala.fldGroupName 
from tblKala inner join tblGroupKala ON tblGroupKala.fldGroupId=tblKala.fldCodeGroup
where tblKala.fldCodeKala=#TempBetfkikGroupKala.fldCodeKala	

update #TempBetfkikGroupKala set fldCodeGroupAshkhas=tblGroupAshkhas.fldGroupId,fldNameGroupAshkhas=tblGroupAshkhas.fldGroupName
from tblTafzili inner join tblGroupAshkhas ON tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
where tblTafzili.fldCodeTafzili=#TempBetfkikGroupKala.fldCodeTafzili	
	
	
update #TempBetfkikGroupKala set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempBetfkikGroupKala.fldCodetafzili=tbl5.fldCodeTafzili


--پاک کردن گروه کالاهایی که در گزارش نیستن
if @ListGroupKala<>''
	begin
		declare @StrDeleteGroupKala varchar(5000)
		set  @StrDeleteGroupKala='delete from #TempBetfkikGroupKala
		where '+ @ListGroupKala + ''
		execute(@StrDeleteGroupKala)
	end
if @ListCodeAshkhas<>''
	begin
		declare @StrDeleteGroupAshkhas varchar(5000)
		set  @StrDeleteGroupAshkhas='delete from #TempBetfkikGroupKala 
		where '+ @ListCodeAshkhas + ''
		execute(@StrDeleteGroupAshkhas)
	end
if @ListCodeAnbar<>''
	begin
		declare @StrDeleteAnbar varchar(5000)
		set  @StrDeleteAnbar='delete from #TempBetfkikGroupKala
		where '+ @ListCodeAnbar + ''
		execute(@StrDeleteAnbar)
	end
	



						 
--insert into #TempShowBetfkikGroupKala(fldMablaghKhalesForoosh,fldCodeTafzili,fldSharhTafzili
--,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldAddress)
--select sum(fldMablaghKhalesForoosh) as fldmSum,fldCodeTafzili,fldSharhTafzili
--,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldAddress from #TempBetfkikGroupKala
--Group By fldCodeTafzili,fldSharhTafzili
--,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldAddress


	
--update #TempShowBetfkikGroupKala set fldCodeTafzili=#TempBetfkikGroupKala.fldCodeTafzili
--	from #TempBetfkikGroupKala where #TempShowBetfkikGroupKala.fldSharhTafzili=#TempBetfkikGroupKala.fldSharhTafzili

--update #TempShowBetfkikGroupKala set fldCodeAnbar=#TempBetfkikGroupKala.fldCodeAnbar,fldAnbarName=#TempBetfkikGroupKala.fldAnbarName
--	from #TempBetfkikGroupKala where #TempShowBetfkikGroupKala.fldCodeTafzili=#TempBetfkikGroupKala.fldCodeTafzili

	
	

--update #TempShowBetfkikGroupKala set fldCodeGroupKala=#TempBetfkikGroupKala.fldCodeGroupKala, fldGroupKalaName=#TempBetfkikGroupKala.fldGroupKalaName 
--from #TempBetfkikGroupKala 
--where #TempBetfkikGroupKala.fldCodeTafzili=#TempBetfkikGroupKala.fldCodeTafzili	


update #TempBetfkikGroupKala set fldNameVizitor=tblTafzili.fldSharheTafzili from tblTafzili where fldCodeVasete=tblTafzili.fldCodeTafzili

 declare @StrOrder nvarchar(50)
 declare @Select nvarchar(500)



-- Set @Select='select sum(fldMablaghKhalesForoosh) as fldMablaghKhalesForoosh,sum(fldtedad) as fldtedad,fldCodeTafzili,fldSharhTafzili
--,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldShomareTell,fldAddress,fldCodeVasete,fldNameVizitor from #TempBetfkikGroupKala
--Group By fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldShomareTell,fldAddress,fldCodeVasete,fldNameVizitor '

--Select fldCodeTafzili,fldSharhTafzili,fldCodeGroupKala,fldGroupKalaName
--,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldCodeAnbar,fldAnbarName,fldShomareTell,fldMablaghKhalesForoosh,fldtedad,fldAddress from #TempBetfkikGroupKala 

--if @Order=0 
--	set @StrOrder=' order by fldMablaghKhalesForoosh desc'
--else if @Order=1 	
--	set @StrOrder=' order by fldMablaghKhalesForoosh asc'

--execute(@select)

	select sum(fldMablaghKhalesForoosh) as fldMablaghKhalesForoosh,sum(fldtedad) as fldtedad,fldCodeTafzili,fldSharhTafzili
		,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldShomareTell,fldAddress,fldCodeVasete,fldNameVizitor from #TempBetfkikGroupKala
		Group By fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas,fldNameGroupAshkhas,fldShomareTell,fldAddress,fldCodeVasete,fldNameVizitor

end
GO

-- ===============================================
-- SP: [dbo].[z164ShowReportDaryaft]
-- ===============================================
IF OBJECT_ID(N'dbo.z164ShowReportDaryaft', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z164ShowReportDaryaft] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z164ShowReportDaryaft]

	@ListAshkhas varchar(5000)=null,
	@ListVasete varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@DateAz varchar(50),
	@DateTa varchar(50),
	@MablaghAzNaghd decimal, 
	@MablaghTaNaghd decimal,
	@MablaghAzBank decimal,
	@MablaghTaBank decimal,  
	@MablaghAzCheck decimal, 
	@MablaghTaCheck decimal, 
	@MablaghAzTakhfif decimal, 
	@MablaghTaTakhfif decimal, 
	@MablaghAzKol decimal,  
	@MablaghTaKol decimal


as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;

create table #TempShowSandough(
fldCodeSandough bigint,
fldNameSandough NVarchar(100) COLLATE Persian_100_CI_AS
)
create table #TempShowBank(
fldCodeBank bigint,
fldNameBank NVarchar(100) COLLATE Persian_100_CI_AS

)

create table #TempSumKol(
fldShomareDaryaft bigint,
fldMablaghKol decimal

)
create table #TempShowCheck(
fldShomareDaryaft bigint,
fldMablaghCheck decimal
)
create table #TempShowUser1(
id bigint,
fldCodeUser bigint,
fldNameUser NVarchar(100) COLLATE Persian_100_CI_AS,
fldRadif bigint,
fldShomareDaryaft bigint

)

create table #TempShowUser2(
id bigint,
fldCodeUser bigint,
fldNameUser NVarchar(100) COLLATE Persian_100_CI_AS,
fldRadif bigint,
fldShomareDaryaft bigint

)

create table #TempShow(
fldShomareDaryaft bigint,
fldShomareSanad bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldDate NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeSandough bigint,
fldNameSandough NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablaghSandough decimal,
fldCodeBank bigint,
fldNameBank NVarchar(100) COLLATE Persian_100_CI_AS,
fldShenaseBank bigint,
fldMablaghBank decimal,
fldMablaghCheck decimal,
fldMablaghKol decimal,
fldCodeUser bigint,
fldNameUser NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablaghTakhfif decimal,
fldSharhTakhfif NVarchar(200) COLLATE Persian_100_CI_AS,
fldCodeVasete bigint,
fldNameVasete NVarchar(100) COLLATE Persian_100_CI_AS
)
delete #TempShow
delete #TempShowBank


update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')

insert into #TempShow(fldShomareDaryaft,fldShomareSanad,fldCodeTafzili,fldSharhTafzili,
fldDate,fldCodeSandough,fldNameSandough,fldMablaghSandough,fldCodeBank,fldNameBank,fldShenaseBank,
fldMablaghBank,fldMablaghCheck ,
fldMablaghKol,fldCodeUser,fldNameUser,fldMablaghTakhfif,fldSharhTakhfif,fldCodeVasete,fldNameVasete)
select distinct dbo.tblDaryaft.fldShomareDaryaft,dbo.tblDaryaft.fldShomareSanad,
dbo.tblDaryaft.fldCodeTafzili,dbo.tblTafzili.fldSharheTafzili,
SUBSTRING(CONVERT(nvarchar,dbo.tblSodooreSanad.fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, dbo.tblSodooreSanad.fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, dbo.tblSodooreSanad.fldDate), 7, 2) AS fldDate
,NULL as fldCodeSandough,Null as fldNameSandough,0 as fldMablaghSandough,NULL as fldCodeBank,'' as fldNameBank,NULL as fldShenaseBank
,0 as fldMablaghBank,0 as fldMablaghCheck ,0 as fldMablaghKol
,NULL as fldCodeUser,'' as fldNameUser,0 as fldMablaghTakhfif,'' as fldSharhTakhfif,dbo.tblSodooreSanad.fldVasete,'' as fldNameVasete
from tblDaryaft
inner join dbo.tblTafzili on dbo.tblDaryaft.fldCodeTafzili=dbo.tblTafzili.fldCodeTafzili
inner join dbo.tblSodooreSanad on dbo.tblDaryaft.fldShomareSanad=dbo.tblSodooreSanad.fldSanad  and dbo.tblSodooreSanad.fldDate between @DateAz and @DateTa


if @ListAshkhas<>''
		      begin
		       declare @StrDeleteAshkhas varchar(5000)
		        set  @StrDeleteAshkhas='delete from #TempShow 
		            where '+ @ListAshkhas + ''
					execute(@StrDeleteAshkhas)
		      end


		if @ListVasete<>''
		      begin
		       declare @StrDeleteVaste varchar(5000)
		        set  @StrDeleteVaste='delete from #TempShow 
		            where '+ @ListVasete + ''
					execute(@StrDeleteVaste)
		      end




		

	--select * from tblDaryaft
	--select * from tblSodooreSanad
	--select * from #TempShow
	--select * from #TempShowBank
	--------------------------Sandough-------------------------------------
	
		declare @strCodeKoleHesabSandough nvarchar(10)
	execute CodeKolHesab 'sandoogh',@strCodeKoleHesabSandough output
		UPDATE       #TempShow
		SET                fldCodeSandough = tblSodooreSanad.fldMoinKamel,				
						   fldMablaghSandough= tblSodooreSanad.fldBedehkar				
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad 
								where tblSodooreSanad.fldCodeKol=@strCodeKoleHesabSandough


insert into #TempShowSandough(fldCodeSandough,fldNameSandough)


	select[fldCodeHesab], [fldSharheHesab] as fldNameBank from tblKolMoin
		where  fldCodeHesab like @strCodeKoleHesabSandough + '%' and len(fldCodeHesab)>len(@strCodeKoleHesabSandough)
		order by fldCodeHesab
				
		UPDATE       #TempShow
		SET                fldNameSandough = #TempShowSandough.fldNameSandough
																   			
		FROM           #TempShowSandough    INNER JOIN
								#TempShow  ON #TempShowSandough.fldCodeSandough=#TempShow.fldCodeSandough 
							
--------------------------------Bank----------------------------------------
			declare @strCodeKoleHesab nvarchar(10)
	execute CodeKolHesab 'bank',@strcodekolehesab output
			
			UPDATE       #TempShow
		SET                fldCodeBank = tblSodooreSanad.fldMoinKamel,	
						  fldShenaseBank=tblSodooreSanad.fldShomarePeigiri,
						  fldMablaghBank=tblSodooreSanad.fldBedehkar											   			
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldCodeKol=@strCodeKoleHesab
								where tblSodooreSanad.fldCodeKol=@strCodeKoleHesab

 	

	insert into #TempShowBank(fldNameBank,fldCodeBank)
	select [fldSharheHesab] as fldNameBank,[fldCodeHesab] from tblKolMoin
		where  fldCodeHesab like @strCodeKoleHesab + '%' and len(fldCodeHesab)>len(@strCodeKoleHesab)
		order by fldCodeHesab
				
		UPDATE       #TempShow
		SET                fldNameBank = #TempShowBank.fldNameBank
																   			
		FROM           #TempShowBank    INNER JOIN
								#TempShow  ON #TempShowBank.fldCodeBank=#TempShow.fldCodeBank 
								
-----------------------------------Check-------------------------------------------
declare @strCodeKoleHesabCheack nvarchar(10)
	execute CodeKolHesab 'check',@strCodeKoleHesabCheack output
		
	insert into #TempShowCheck(fldShomareDaryaft,fldMablaghCheck)
	select  #TempShow.fldShomareDaryaft,tblSodooreSanad.fldBedehkar from  tblSodooreSanad    INNER JOIN
		#TempShow  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheack
			where tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheack

			--select * from tblCheckeDaryafti


	UPDATE       #TempShow
		SET              
						  fldMablaghCheck=#TempShowCheck.fldMablaghCheck
		FROM           #TempShow   INNER JOIN
								#TempShowCheck  ON #TempShowCheck.fldShomareDaryaft=#TempShow.fldShomareDaryaft 
								where #TempShowCheck.fldShomareDaryaft=#TempShow.fldShomareDaryaft


	--insert into #TempShowCheck(fldShomareDaryaft,fldShomareCheck,fldShomareHesab,fldDateSarResidCheck)
	--			select fldShomareDaryaft,fldShomareCheck,fldShomareHesab,
	--						 SUBSTRING(CONVERT(nvarchar,fldDateSarResid), 1, 4) + '/' +
	--						 SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 5, 2) + '/' + 
	--						 SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 7, 2) AS fldDateSarResid
	--			from tblCheckeDaryafti

	--UPDATE       #TempShow
	--	SET              
	--					  fldShomareCheck=#TempShowCheck.fldShomareCheck	,
	--					  fldShomareHesab=#TempShowCheck.fldShomareHesab,
	--					  fldDateSarResidCheck=#TempShowCheck.fldDateSarResidCheck								   			
	--	FROM           #TempShow   INNER JOIN
	--							#TempShowCheck  ON #TempShow.fldShomareDaryaft=#TempShowCheck.fldShomareDaryaft
	--							where #TempShow.fldShomareDaryaft=#TempShowCheck.fldShomareDaryaft

--------------------------------Takhfif----------------------------------	
declare @strCodeKoleHesabTakhfif nvarchar(10)
	execute CodeMoinHesab'takhfifatedaryaft',@strCodeKoleHesabTakhfif output

	UPDATE       #TempShow
		SET              
						  fldMablaghTakhfif=tblSodooreSanad.fldBedehkar,
						  fldSharhTakhfif=tblSodooreSanad.fldSharh
						  							   			
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldMoinKamel=@strCodeKoleHesabTakhfif
								where tblSodooreSanad.fldMoinKamel=@strCodeKoleHesabTakhfif
----------------------------Vasete--------------------------------------
	UPDATE       #TempShow
		SET              
					
						  fldNameVasete=viewLoadVizitor.fldSharheTafzili
						  							   			
		FROM           #TempShow   INNER JOIN
								viewLoadVizitor  ON viewLoadVizitor.fldCodeTafzili=#TempShow.fldCodeVasete 

-----------------------------Karbar-------------------------------------


delete #TempShowUser1
delete #TempShowUser2



insert into #TempShowUser1(id,fldShomareDaryaft)
SELECT         MAX(id) AS id ,fldShomare
FROM            tblAmalkardekarbar 
WHERE        (fldNameForm = 'دریافت') AND (NoeAmaliat = 'جدید')
GROUP BY fldShomare
ORDER BY fldShomare

insert into #TempShowUser2(id,fldShomareDaryaft)
SELECT         MAX(id) AS id ,fldShomare
FROM            tblAmalkardekarbar 
WHERE        (fldNameForm = 'دریافت') AND (NoeAmaliat = 'ویرایش')
GROUP BY fldShomare
ORDER BY fldShomare

insert into #TempShowUser1(id,fldShomareDaryaft)
select id,fldShomareDaryaft from #TempShowUser2 where fldShomareDaryaft not in(select fldShomareDaryaft from #TempShowUser1)

update #TempShowUser1 Set 
	fldCodeUser=tblAmalkardekarbar.fldCodeKarbar,
	fldNameUser=tblAmalkardekarbar.fldNameKarbar					  							   			
		FROM           #TempShowUser1   INNER JOIN
								tblAmalkardekarbar  ON tblAmalkardekarbar.fldShomare=#TempShowUser1.fldShomareDaryaft
								where tblAmalkardekarbar.id=#TempShowUser1.id


update #TempShow Set 
	fldCodeUser=#TempShowUser1.fldCodeUser,
	fldNameUser=#TempShowUser1.fldNameUser
						  							   			
		FROM           #TempShow   INNER JOIN
								#TempShowUser1  ON #TempShowUser1.fldShomareDaryaft=#TempShow.fldShomareDaryaft  



			  if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end
-----------------------------fldMablaghKol----------------------------------------
declare @SumMablaghKol decimal


UPDATE       #TempShow
		SET              
						  fldMablaghKol=(#TempShow.fldMablaghSandough+#TempShow.fldMablaghBank+#TempShow.fldMablaghCheck-#TempShow.fldMablaghTakhfif)
						  
						  							   			
		FROM           #TempShow


-----------------------------------------------------------------------------------------------------------------------------------------------


SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareDaryaft) as fldRadif,fldShomareDaryaft,fldShomareSanad,fldCodeTafzili,fldSharhTafzili,fldDate  
,fldCodeSandough,fldNameSandough,fldMablaghSandough,fldCodeBank,fldNameBank,fldShenaseBank,
fldMablaghBank,fldMablaghCheck,fldMablaghKol,fldCodeUser,fldNameUser,fldMablaghTakhfif,fldSharhTakhfif,fldCodeVasete,fldNameVasete  
FROM #TempShow  
where 
fldMablaghSandough between CONVERT(nvarchar(50),@MablaghAzNaghd) and CONVERT(nvarchar(50),@MablaghTaNaghd) and 
fldMablaghBank between  CONVERT(nvarchar(50),@MablaghAzBank)  and CONVERT(nvarchar(50),@MablaghTaBank) and 
fldMablaghCheck between  CONVERT(nvarchar(50),@MablaghAzCheck)  and CONVERT(nvarchar(50),@MablaghTaCheck) and 
fldMablaghTakhfif between  CONVERT(nvarchar(50),@MablaghAzTakhfif)  and CONVERT(nvarchar(50),@MablaghTaTakhfif) and 
fldMablaghKol between  CONVERT(nvarchar(50),@MablaghAzKol)  and CONVERT(nvarchar(50),@MablaghTaKol)



END
GO

-- ===============================================
-- SP: [dbo].[z164ShowReportDaryaft_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z164ShowReportDaryaft_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z164ShowReportDaryaft_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z164ShowReportDaryaft_WithUserCode]

	@ListAshkhas varchar(5000)=null,
	@ListVasete varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@DateAz varchar(50),
	@DateTa varchar(50),
	@MablaghAzNaghd decimal, 
	@MablaghTaNaghd decimal,
	@MablaghAzBank decimal,
	@MablaghTaBank decimal,  
	@MablaghAzCheck decimal, 
	@MablaghTaCheck decimal, 
	@MablaghAzTakhfif decimal, 
	@MablaghTaTakhfif decimal, 
	@MablaghAzKol decimal,  
	@MablaghTaKol decimal,
	@userCode bigint


as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;

create table #TempShowSandough(
fldCodeSandough bigint,
fldNameSandough NVarchar(100) COLLATE Persian_100_CI_AS
)
create table #TempShowBank(
fldCodeBank bigint,
fldNameBank NVarchar(100) COLLATE Persian_100_CI_AS

)

create table #TempSumKol(
fldShomareDaryaft bigint,
fldMablaghKol decimal

)
create table #TempShowCheck(
fldShomareDaryaft bigint,
fldMablaghCheck decimal
)
create table #TempShowUser1(
id bigint,
fldCodeUser bigint,
fldNameUser NVarchar(100) COLLATE Persian_100_CI_AS,
fldRadif bigint,
fldShomareDaryaft bigint

)

create table #TempShowUser2(
id bigint,
fldCodeUser bigint,
fldNameUser NVarchar(100) COLLATE Persian_100_CI_AS,
fldRadif bigint,
fldShomareDaryaft bigint

)

create table #TempShow(
fldShomareDaryaft bigint,
fldShomareSanad bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(200) COLLATE Persian_100_CI_AS,
fldDate NVarchar(150) COLLATE Persian_100_CI_AS,
fldCodeSandough bigint,
fldNameSandough NVarchar(150) COLLATE Persian_100_CI_AS,
fldMablaghSandough decimal,
fldCodeBank bigint,
fldNameBank NVarchar(150) COLLATE Persian_100_CI_AS,
fldShenaseBank nvarchar(50),
fldMablaghBank decimal,
fldMablaghCheck decimal,
fldMablaghKol decimal,
fldCodeUser bigint,
fldNameUser NVarchar(150) COLLATE Persian_100_CI_AS,
fldMablaghTakhfif decimal,
fldSharhTakhfif NVarchar(200) COLLATE Persian_100_CI_AS,
fldCodeVasete bigint,
fldNameVasete NVarchar(100) COLLATE Persian_100_CI_AS
)
delete #TempShow
delete #TempShowBank



update         tblAmalkardekarbar
set fldsanad=tblforoosh.fldShomareSanad from tblforoosh
WHERE        (fldNameForm = N'فروش') AND (NoeAmaliat = N'جدید') and tblforoosh.fldShomareFactorForoosh=tblAmalkardekarbar.fldShomare



UPDATE       tblAmalkardekarbar
SET                fldSanad = tblBargashtAzForoosh.fldShomareSanad
FROM            tblBargashtAzForoosh INNER JOIN
                         tblAmalkardekarbar ON tblBargashtAzForoosh.fldShomareFactorForoosh= tblAmalkardekarbar.fldShomare
WHERE        (tblAmalkardekarbar.fldNameForm = N'خرید') AND (tblAmalkardekarbar.NoeAmaliat = N'جدید') and tblBargashtAzForoosh.fldShomareFactorForoosh=tblAmalkardekarbar.fldShomare



UPDATE       tblAmalkardekarbar
SET                fldSanad = tblKharid.fldShomareSanad
FROM            tblKharid INNER JOIN
                         tblAmalkardekarbar ON tblKharid.fldShomareFactorKharid= tblAmalkardekarbar.fldShomare
WHERE        (tblAmalkardekarbar.fldNameForm = N'خرید') AND (tblAmalkardekarbar.NoeAmaliat = N'جدید') and tblKharid.fldShomareFactorKharid=tblAmalkardekarbar.fldShomare


UPDATE       tblAmalkardekarbar
SET                fldSanad = tblBargashtAzKharid.fldShomareSanad
FROM            tblBargashtAzKharid INNER JOIN
                         tblAmalkardekarbar ON tblBargashtAzKharid.fldShomareFactorKharid= tblAmalkardekarbar.fldShomare
WHERE        (tblAmalkardekarbar.fldNameForm = N'برگشت از خرید') AND (tblAmalkardekarbar.NoeAmaliat = N'جدید') and tblBargashtAzKharid.fldShomareFactorKharid=tblAmalkardekarbar.fldShomare




declare @CodeSandoogh nvarchar(20),@CodeBank nvarchar(20),@CodeCheck nvarchar(20),@CodeTakhfif nvarchar(20)

	execute CodeKolHesab 'sandoogh',@CodeSandoogh output
	execute CodeKolHesab 'bank',@CodeBank output
	execute CodeKolHesab 'check',@CodeCheck output
	execute CodeMoinHesab 'takhfifatedaryaft',@CodeTakhfif output


update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')

insert into #TempShow(fldShomareDaryaft,fldShomareSanad,fldCodeTafzili,fldSharhTafzili,
fldDate,fldCodeSandough,fldNameSandough,fldMablaghSandough,fldCodeBank,fldNameBank,fldShenaseBank,
fldMablaghBank,fldMablaghCheck ,
fldMablaghKol,fldCodeUser,fldNameUser,fldMablaghTakhfif,fldSharhTakhfif,fldCodeVasete,fldNameVasete)
select  dbo.tblDaryaft.fldShomareDaryaft,dbo.tblDaryaft.fldShomareSanad,
dbo.tblDaryaft.fldCodeTafzili,dbo.tblTafzili.fldSharheTafzili,
SUBSTRING(CONVERT(nvarchar,dbo.tblSodooreSanad.fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, dbo.tblSodooreSanad.fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, dbo.tblSodooreSanad.fldDate), 7, 2) AS fldDate
,NULL as fldCodeSandough,Null as fldNameSandough,0 as fldMablaghSandough,tblSodooreSanad.fldMoinKamel as fldCodeBank,'' as fldNameBank,fldshomarepeigiri as fldShenaseBank
,tblSodooreSanad.fldBedehkar as fldMablaghBank,0 as fldMablaghCheck ,0 as fldMablaghKol
,NULL as fldCodeUser,'' as fldNameUser,0 as fldMablaghTakhfif,'' as fldSharhTakhfif,dbo.tblSodooreSanad.fldVasete,'' as fldNameVasete
from tblDaryaft
inner join dbo.tblTafzili on dbo.tblDaryaft.fldCodeTafzili=dbo.tblTafzili.fldCodeTafzili
inner join dbo.tblSodooreSanad on dbo.tblDaryaft.fldShomareSanad=dbo.tblSodooreSanad.fldSanad  and dbo.tblSodooreSanad.fldDate between @DateAz and @DateTa  and (fldCodeKol = @CodeSandoogh or fldCodeKol=@CodeBank or fldCodeKol=@CodeCheck or fldMoinKamel =@CodeTakhfif)


if @ListAshkhas<>''
		      begin
		       declare @StrDeleteAshkhas varchar(5000)
		        set  @StrDeleteAshkhas='delete from #TempShow 
		            where '+ @ListAshkhas + ''
					execute(@StrDeleteAshkhas)
		      end


if @ListVasete<>''
		begin
		declare @StrDeleteVaste varchar(5000)

		delete #TempShow  where fldCodeVasete IS NULL

		set  @StrDeleteVaste='delete from #TempShow 
		    where '+ @ListVasete + ''
			execute(@StrDeleteVaste)
		end




		

	--select * from tblDaryaft
	--select * from tblSodooreSanad
	--select * from #TempShow
	--select * from #TempShowBank
	--------------------------Sandough-------------------------------------
	
		declare @strCodeKoleHesabSandough nvarchar(10)
	execute CodeKolHesab 'sandoogh',@strCodeKoleHesabSandough output
		UPDATE       #TempShow
		SET                fldCodeSandough = tblSodooreSanad.fldMoinKamel,				
						   fldMablaghSandough= tblSodooreSanad.fldBedehkar				
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad 
								where tblSodooreSanad.fldCodeKol=@strCodeKoleHesabSandough


insert into #TempShowSandough(fldCodeSandough,fldNameSandough)


	select[fldCodeHesab], [fldSharheHesab] as fldNameBank from tblKolMoin
		where  fldCodeHesab like @strCodeKoleHesabSandough + '%' and len(fldCodeHesab)>len(@strCodeKoleHesabSandough)
		order by fldCodeHesab
				
		UPDATE       #TempShow
		SET                fldNameSandough = #TempShowSandough.fldNameSandough
																   			
		FROM           #TempShowSandough    INNER JOIN
								#TempShow  ON #TempShowSandough.fldCodeSandough=#TempShow.fldCodeSandough 
							
--------------------------------Bank----------------------------------------
	declare @strCodeKoleHesab nvarchar(10)
	execute CodeKolHesab 'bank',@strcodekolehesab output
	update #TempShow set fldCodeBank=0,fldMablaghBank=0,fldMablaghCheck=0 Where left(fldCodeBank,3)=@strCodeKoleHesabSandough
	update #TempShow set fldCodeSandough=0,fldMablaghSandough=0,fldNameSandough='',fldMablaghCheck=0 Where left(fldCodeBank,3)=@strcodekolehesab

 	

	insert into #TempShowBank(fldNameBank,fldCodeBank)
	select [fldSharheHesab] as fldNameBank,[fldCodeHesab] from tblKolMoin
		where  fldCodeHesab like @strCodeKoleHesab + '%' and len(fldCodeHesab)>len(@strCodeKoleHesab)
		order by fldCodeHesab
				
		UPDATE       #TempShow
		SET                fldNameBank = #TempShowBank.fldNameBank
																   			
		FROM           #TempShowBank    INNER JOIN
								#TempShow  ON #TempShowBank.fldCodeBank=#TempShow.fldCodeBank 
								
-----------------------------------Check-------------------------------------------
declare @strCodeKoleHesabCheack nvarchar(10)
	execute CodeKolHesab 'check',@strCodeKoleHesabCheack output

	update #TempShow set fldCodeBank=0,fldMablaghBank=0,fldCodeSandough=0,fldMablaghSandough=0,fldNameSandough='' Where left(fldCodeBank,3)=@strCodeKoleHesabCheack
	update #TempShow set fldCodeSandough=0,fldMablaghSandough=0,fldNameSandough='' Where left(fldCodeBank,3)=@strCodeKoleHesabCheack
	
		
	insert into #TempShowCheck(fldShomareDaryaft,fldMablaghCheck)
	select  #TempShow.fldShomareDaryaft,tblSodooreSanad.fldBedehkar from  tblSodooreSanad    INNER JOIN
		#TempShow  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheack
			where tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheack

			--select * from tblCheckeDaryafti


	UPDATE       #TempShow
		SET              
						  fldMablaghCheck=#TempShowCheck.fldMablaghCheck
		FROM           #TempShow   INNER JOIN
								#TempShowCheck  ON #TempShowCheck.fldShomareDaryaft=#TempShow.fldShomareDaryaft 
								where #TempShowCheck.fldShomareDaryaft=#TempShow.fldShomareDaryaft

	update #TempShow set fldMablaghCheck=0 where fldMablaghBank>0 or fldMablaghSandough>0
--update #TempShow set fldMablaghCheck=0 Where left(fldCodeBank,3)<>@strCodeKoleHesabCheack
	--insert into #TempShowCheck(fldShomareDaryaft,fldShomareCheck,fldShomareHesab,fldDateSarResidCheck)
	--			select fldShomareDaryaft,fldShomareCheck,fldShomareHesab,
	--						 SUBSTRING(CONVERT(nvarchar,fldDateSarResid), 1, 4) + '/' +
	--						 SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 5, 2) + '/' + 
	--						 SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 7, 2) AS fldDateSarResid
	--			from tblCheckeDaryafti

	--UPDATE       #TempShow
	--	SET              
	--					  fldShomareCheck=#TempShowCheck.fldShomareCheck	,
	--					  fldShomareHesab=#TempShowCheck.fldShomareHesab,
	--					  fldDateSarResidCheck=#TempShowCheck.fldDateSarResidCheck								   			
	--	FROM           #TempShow   INNER JOIN
	--							#TempShowCheck  ON #TempShow.fldShomareDaryaft=#TempShowCheck.fldShomareDaryaft
	--							where #TempShow.fldShomareDaryaft=#TempShowCheck.fldShomareDaryaft

--------------------------------Takhfif----------------------------------	
declare @strCodeKoleHesabTakhfif nvarchar(10)
	execute CodeMoinHesab'takhfifatedaryaft',@strCodeKoleHesabTakhfif output

	UPDATE       #TempShow
		SET              
						  fldMablaghTakhfif=tblSodooreSanad.fldBedehkar,
						  fldSharhTakhfif=tblSodooreSanad.fldSharh
						  							   			
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldMoinKamel=@strCodeKoleHesabTakhfif
								where tblSodooreSanad.fldMoinKamel=@strCodeKoleHesabTakhfif
----------------------------Vasete--------------------------------------
	UPDATE       #TempShow
		SET              
					
						  fldNameVasete=viewLoadVizitor.fldSharheTafzili
						  							   			
		FROM           #TempShow   INNER JOIN
								viewLoadVizitor  ON viewLoadVizitor.fldCodeTafzili=#TempShow.fldCodeVasete 

	update #TempShow set fldMablaghTakhfif=0 where  fldCodeBank<>@strCodeKoleHesabTakhfif
	update #TempShow set fldMablaghBank=0 ,fldMablaghCheck=0,fldMablaghSandough=0,fldcodebank=0,fldNameBank='',fldCodeSandough=0,fldNameSandough='' where fldCodeBank=@strCodeKoleHesabTakhfif
	

-----------------------------Karbar-------------------------------------


delete #TempShowUser1
delete #TempShowUser2



insert into #TempShowUser1(id,fldShomareDaryaft)
SELECT         MAX(id) AS id ,fldShomare
FROM            tblAmalkardekarbar 
WHERE        (fldNameForm = 'دریافت') AND (NoeAmaliat = 'جدید')
GROUP BY fldShomare
ORDER BY fldShomare

insert into #TempShowUser2(id,fldShomareDaryaft)
SELECT         MAX(id) AS id ,fldShomare
FROM            tblAmalkardekarbar 
WHERE        (fldNameForm = 'دریافت') AND (NoeAmaliat = 'ویرایش')
GROUP BY fldShomare
ORDER BY fldShomare

insert into #TempShowUser1(id,fldShomareDaryaft)
select id,fldShomareDaryaft from #TempShowUser2 where fldShomareDaryaft not in(select fldShomareDaryaft from #TempShowUser1)

update #TempShowUser1 Set 
	fldCodeUser=tblAmalkardekarbar.fldCodeKarbar,
	fldNameUser=tblAmalkardekarbar.fldNameKarbar					  							   			
		FROM           #TempShowUser1   INNER JOIN
								tblAmalkardekarbar  ON tblAmalkardekarbar.fldShomare=#TempShowUser1.fldShomareDaryaft
								where tblAmalkardekarbar.id=#TempShowUser1.id


update #TempShow Set 
	fldCodeUser=#TempShowUser1.fldCodeUser,
	fldNameUser=#TempShowUser1.fldNameUser
						  							   			
		FROM           #TempShow   INNER JOIN
								#TempShowUser1  ON #TempShowUser1.fldShomareDaryaft=#TempShow.fldShomareDaryaft  





		--delete from #TempShow where 
-----------------------------fldMablaghKol----------------------------------------
declare @SumMablaghKol decimal


UPDATE       #TempShow
		SET              
						  fldMablaghKol=(#TempShow.fldMablaghSandough+#TempShow.fldMablaghBank+#TempShow.fldMablaghCheck)
						  
						  							   			
		FROM           #TempShow


-----------------------------------------------------------------------------------------------------------------------------------------------
-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################
delete from #TempShow where fldCodeTafzili not in (select code from @accessCodes)
-- ##########################################################

begin try
	update #TempShow set fldcodeuser=tblAmalkardekarbar.fldCodeKarbar,fldNameUser=tblAmalkardekarbar.fldNameKarbar from tblAmalkardekarbar where #TempShow.fldShomareSanad=tblAmalkardekarbar.fldSanad
end try
begin catch

end catch


if @ListKarbaran<>''
		begin
		declare @StrDeleteKarbar varchar(5000)
		set  @StrDeleteKarbar='delete from #TempShow 
		    where '+ @ListKarbaran + ''
			execute(@StrDeleteKarbar)
		end

SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareDaryaft) as fldRadif,fldShomareDaryaft,fldShomareSanad,fldCodeTafzili,fldSharhTafzili,fldDate  
,fldCodeSandough,fldNameSandough,fldMablaghSandough,fldCodeBank,fldNameBank,fldShenaseBank,
fldMablaghBank,fldMablaghCheck,fldMablaghKol,fldCodeUser,fldNameUser,fldMablaghTakhfif,fldSharhTakhfif,fldCodeVasete,fldNameVasete  
FROM #TempShow  
where 
fldMablaghSandough between CONVERT(nvarchar(50),@MablaghAzNaghd) and CONVERT(nvarchar(50),@MablaghTaNaghd) and 
fldMablaghBank between  CONVERT(nvarchar(50),@MablaghAzBank)  and CONVERT(nvarchar(50),@MablaghTaBank) and 
fldMablaghCheck between  CONVERT(nvarchar(50),@MablaghAzCheck)  and CONVERT(nvarchar(50),@MablaghTaCheck) and 
fldMablaghTakhfif between  CONVERT(nvarchar(50),@MablaghAzTakhfif)  and CONVERT(nvarchar(50),@MablaghTaTakhfif) and 
fldMablaghKol between  CONVERT(nvarchar(50),@MablaghAzKol)  and CONVERT(nvarchar(50),@MablaghTaKol) 



END
GO

-- ===============================================
-- SP: [dbo].[z165ShowReportPardakht]
-- ===============================================
IF OBJECT_ID(N'dbo.z165ShowReportPardakht', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z165ShowReportPardakht] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z165ShowReportPardakht]

	@ListAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@DateAz varchar(50),
	@DateTa varchar(50),
	@MablaghAzNaghd decimal, 
	@MablaghTaNaghd decimal,
	@MablaghAzBank decimal,
	@MablaghTaBank decimal,  
	@MablaghAzCheck decimal, 
	@MablaghTaCheck decimal, 
	@MablaghAzTakhfif decimal, 
	@MablaghTaTakhfif decimal, 
	@MablaghAzKol decimal,  
	@MablaghTaKol decimal


as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;

create table #TempShowSandough(
fldCodeSandough bigint,
fldNameSandough NVarchar(100) COLLATE Persian_100_CI_AS
)
create table #TempShowBank(
fldCodeBank bigint,
fldNameBank NVarchar(100) COLLATE Persian_100_CI_AS

)

create table #TempSumKol(
fldShomarePardakht bigint,
fldMablaghKol decimal

)
create table #TempShowCheck(
fldShomarePardakht bigint,
fldMablaghCheck decimal

)

create table #TempShowUser1(
id bigint,
fldCodeUser bigint,
fldNameUser NVarchar(100) COLLATE Persian_100_CI_AS,
fldRadif bigint,
fldShomarePardakht bigint

)

create table #TempShowUser2(
id bigint,
fldCodeUser bigint,
fldNameUser NVarchar(100) COLLATE Persian_100_CI_AS,
fldRadif bigint,
fldShomarePardakht bigint

)

create table #TempShow(
fldShomarePardakht bigint,
fldShomareSanad bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldDate NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeSandough bigint,
fldNameSandough NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablaghSandough decimal,
fldCodeBank bigint,
fldNameBank NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablaghBank decimal,
fldMablaghCheck decimal,
fldMablaghCheckVagozari decimal,
fldMablaghKol decimal,
fldCodeUser bigint,
fldNameUser NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablaghTakhfif decimal,
fldSharhTakhfif NVarchar(200) COLLATE Persian_100_CI_AS
)
delete #TempShow
delete #TempShowBank


update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')

insert into #TempShow(fldShomarePardakht,fldShomareSanad,fldCodeTafzili,fldSharhTafzili,
fldDate,fldCodeSandough,fldNameSandough,fldMablaghSandough,fldCodeBank,fldNameBank,
fldMablaghBank,fldMablaghCheck ,fldMablaghCheckVagozari,
fldMablaghKol,fldCodeUser,fldNameUser,fldMablaghTakhfif,fldSharhTakhfif)
select distinct dbo.tblPardakht.fldShomarePardakht,dbo.tblPardakht.fldShomareSanad,
dbo.tblPardakht.fldCodeTafzili,dbo.tblTafzili.fldSharheTafzili,
SUBSTRING(CONVERT(nvarchar,dbo.tblSodooreSanad.fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, dbo.tblSodooreSanad.fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, dbo.tblSodooreSanad.fldDate), 7, 2) AS fldDate
,NULL as fldCodeSandough,Null as fldNameSandough,0 as fldMablaghSandough,NULL as fldCodeBank,'' as fldNameBank
,0 as fldMablaghBank,0 as fldMablaghCheck,0 as fldMablaghCheckVagozari ,0 as fldMablaghKol
,NULL as fldCodeUser,'' as fldNameUser,0 as fldMablaghTakhfif,'' as fldSharhTakhfif
from tblPardakht
inner join dbo.tblTafzili on dbo.tblPardakht.fldCodeTafzili=dbo.tblTafzili.fldCodeTafzili
inner join dbo.tblSodooreSanad on dbo.tblPardakht.fldShomareSanad=dbo.tblSodooreSanad.fldSanad  and dbo.tblSodooreSanad.fldDate between @DateAz and @DateTa







		if @ListAshkhas<>''
		      begin
		       declare @StrDeleteAshkhas varchar(5000)
		        set  @StrDeleteAshkhas='delete from #TempShow 
		            where '+ @ListAshkhas + ''
					execute(@StrDeleteAshkhas)
		      end


			
	--select * from tblDaryaft
	--select * from tblSodooreSanad
	--select * from #TempShow
	--select * from #TempShowBank
	--------------------------Sandough-------------------------------------
			declare @strCodeKoleHesabSandough nvarchar(10)
	execute CodeKolHesab 'sandoogh',@strCodeKoleHesabSandough output

		UPDATE       #TempShow
		SET                fldCodeSandough = tblSodooreSanad.fldMoinKamel,				
						   fldMablaghSandough= tblSodooreSanad.fldBestankar				
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad 
								where tblSodooreSanad.fldCodeKol=@strCodeKoleHesabSandough


	
insert into #TempShowSandough(fldCodeSandough,fldNameSandough)


	select[fldCodeHesab], [fldSharheHesab] as fldNameBank from tblKolMoin
		where  fldCodeHesab like @strCodeKoleHesabSandough + '%' and len(fldCodeHesab)>len(@strCodeKoleHesabSandough)
		order by fldCodeHesab
				
		UPDATE       #TempShow
		SET                fldNameSandough = #TempShowSandough.fldNameSandough
																   			
		FROM           #TempShowSandough    INNER JOIN
								#TempShow  ON #TempShowSandough.fldCodeSandough=#TempShow.fldCodeSandough 
							
--------------------------------Bank----------------------------------------
			declare @strCodeKoleHesab nvarchar(10)
	execute CodeKolHesab 'bank',@strcodekolehesab output
		
			UPDATE       #TempShow
		SET                fldCodeBank = tblSodooreSanad.fldMoinKamel,
						  fldMablaghBank=tblSodooreSanad.fldBestankar											   			
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldCodeKol=@strcodekolehesab
								where tblSodooreSanad.fldCodeKol=@strcodekolehesab

 	

	insert into #TempShowBank(fldNameBank,fldCodeBank)
	select [fldSharheHesab],[fldCodeHesab] from tblKolMoin
		Where fldCodeHesab<>@strcodekolehesab and left(fldCodeHesab,len(@strcodekolehesab))=@strcodekolehesab
		order by fldCodeHesab
				
		UPDATE       #TempShow
		SET                fldNameBank = #TempShowBank.fldNameBank
																   			
		FROM           #TempShowBank    INNER JOIN
								#TempShow  ON #TempShowBank.fldCodeBank=#TempShow.fldCodeBank 
								
-----------------------------------Check-------------------------------------------
declare @strCodeKoleHesabCheack nvarchar(10)
	execute CodeKolHesab 'checkpardakhti',@strCodeKoleHesabCheack output
		
	insert into #TempShowCheck(fldShomarePardakht,fldMablaghCheck)
	select  #TempShow.fldShomarePardakht,tblSodooreSanad.fldBestankar from  tblSodooreSanad    INNER JOIN
		#TempShow  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheack
			where tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheack

			--select * from tblCheckeDaryafti


	UPDATE       #TempShow
		SET              
						  fldMablaghCheck=#TempShowCheck.fldMablaghCheck
		FROM           #TempShow   INNER JOIN
								#TempShowCheck  ON #TempShowCheck.fldShomarePardakht=#TempShow.fldShomarePardakht 
								where #TempShowCheck.fldShomarePardakht=#TempShow.fldShomarePardakht

-----------------------------------CheckVagozari-------------------------------------------
	declare @strCodeKoleHesabCheckVagozari nvarchar(10)
	execute CodeKolHesab 'check',@strCodeKoleHesabCheckVagozari output
	--select @strCodeKoleHesabCheckVagozari
	UPDATE       #TempShow
		SET              
						  fldMablaghCheckVagozari=tblSodooreSanad.fldBestankar									   			
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheckVagozari
								where tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheckVagozari
	


--------------------------------Takhfif----------------------------------	
declare @strCodeKoleHesabTakhfif nvarchar(10)
	execute CodeMoinHesab'takhfifatepardakht',@strCodeKoleHesabTakhfif output
	
	UPDATE       #TempShow
		SET              
						  fldMablaghTakhfif=tblSodooreSanad.fldBestankar,
						  fldSharhTakhfif=tblSodooreSanad.fldSharh
						  							   			
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldMoinKamel=@strCodeKoleHesabTakhfif
								where tblSodooreSanad.fldMoinKamel=@strCodeKoleHesabTakhfif

-----------------------------Karbar-------------------------------------


delete #TempShowUser1
delete #TempShowUser2



insert into #TempShowUser1(id,fldShomarePardakht)
SELECT         MAX(id) AS id ,fldShomare
FROM            tblAmalkardekarbar 
WHERE        (fldNameForm = 'پرداخت') AND (NoeAmaliat = 'جدید')
GROUP BY fldShomare
ORDER BY fldShomare

insert into #TempShowUser2(id,fldShomarePardakht)
SELECT         MAX(id) AS id ,fldShomare
FROM            tblAmalkardekarbar 
WHERE        (fldNameForm = 'پرداخت') AND (NoeAmaliat = 'ویرایش')
GROUP BY fldShomare
ORDER BY fldShomare

insert into #TempShowUser1(id,fldShomarePardakht)
select id,fldShomarePardakht from #TempShowUser2 where fldShomarePardakht not in(select fldShomarePardakht from #TempShowUser1)

update #TempShowUser1 Set 
	fldCodeUser=tblAmalkardekarbar.fldCodeKarbar,
	fldNameUser=tblAmalkardekarbar.fldNameKarbar					  							   			
		FROM           #TempShowUser1   INNER JOIN
								tblAmalkardekarbar  ON tblAmalkardekarbar.fldShomare=#TempShowUser1.fldShomarePardakht
								where tblAmalkardekarbar.id=#TempShowUser1.id


update #TempShow Set 
	fldCodeUser=#TempShowUser1.fldCodeUser,
	fldNameUser=#TempShowUser1.fldNameUser
						  							   			
		FROM           #TempShow   INNER JOIN
								#TempShowUser1  ON #TempShowUser1.fldShomarePardakht=#TempShow.fldShomarePardakht  


  	  if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end
-----------------------------fldMablaghKol----------------------------------------
declare @SumMablaghKol decimal


UPDATE       #TempShow
		SET              
						  fldMablaghKol=(#TempShow.fldMablaghSandough+#TempShow.fldMablaghBank+#TempShow.fldMablaghCheck-#TempShow.fldMablaghTakhfif)
						  
						  							   			
		FROM           #TempShow


-----------------------------------------------------------------------------------------------------------------------------------------------
SELECT  ROW_NUMBER() OVER(ORDER BY fldShomarePardakht) as fldRadif,fldShomarePardakht,fldShomareSanad,fldCodeTafzili,fldSharhTafzili,fldDate  
,fldCodeSandough,fldNameSandough,fldMablaghSandough,fldCodeBank,fldNameBank,
fldMablaghBank,fldMablaghCheck ,fldMablaghCheckVagozari,
fldMablaghKol,fldCodeUser,fldNameUser,fldMablaghTakhfif,fldSharhTakhfif
FROM #TempShow  where 
fldMablaghSandough between CONVERT(nvarchar(50),@MablaghAzNaghd) and CONVERT(nvarchar(50),@MablaghTaNaghd) and 
fldMablaghBank between  CONVERT(nvarchar(50),@MablaghAzBank)  and CONVERT(nvarchar(50),@MablaghTaBank) and 
fldMablaghCheck between  CONVERT(nvarchar(50),@MablaghAzCheck)  and CONVERT(nvarchar(50),@MablaghTaCheck) and 
fldMablaghTakhfif between  CONVERT(nvarchar(50),@MablaghAzTakhfif)  and CONVERT(nvarchar(50),@MablaghTaTakhfif) and 
fldMablaghKol between  CONVERT(nvarchar(50),@MablaghAzKol)  and CONVERT(nvarchar(50),@MablaghTaKol)



END
GO

-- ===============================================
-- SP: [dbo].[z165ShowReportPardakht_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z165ShowReportPardakht_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z165ShowReportPardakht_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z165ShowReportPardakht_WithUserCode]

	@ListAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@DateAz varchar(50),
	@DateTa varchar(50),
	@MablaghAzNaghd decimal, 
	@MablaghTaNaghd decimal,
	@MablaghAzBank decimal,
	@MablaghTaBank decimal,  
	@MablaghAzCheck decimal, 
	@MablaghTaCheck decimal, 
	@MablaghAzTakhfif decimal, 
	@MablaghTaTakhfif decimal, 
	@MablaghAzKol decimal,  
	@MablaghTaKol decimal,
	@userCode bigint

as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;

create table #TempShowSandough(
fldCodeSandough bigint,
fldNameSandough NVarchar(100) COLLATE Persian_100_CI_AS
)
create table #TempShowBank(
fldCodeBank bigint,
fldNameBank NVarchar(100) COLLATE Persian_100_CI_AS

)

create table #TempSumKol(
fldShomarePardakht bigint,
fldMablaghKol decimal

)
create table #TempShowCheck(
fldShomarePardakht bigint,
fldMablaghCheck decimal

)

create table #TempShowUser1(
id bigint,
fldCodeUser bigint,
fldNameUser NVarchar(100) COLLATE Persian_100_CI_AS,
fldRadif bigint,
fldShomarePardakht bigint

)

create table #TempShowUser2(
id bigint,
fldCodeUser bigint,
fldNameUser NVarchar(100) COLLATE Persian_100_CI_AS,
fldRadif bigint,
fldShomarePardakht bigint

)

create table #TempShow(
fldShomarePardakht bigint,
fldShomareSanad bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldDate NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeSandough bigint,
fldNameSandough NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablaghSandough decimal,
fldCodeBank bigint,
fldNameBank NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablaghBank decimal,
fldMablaghCheck decimal,
fldMablaghCheckVagozari decimal,
fldMablaghKol decimal,
fldCodeUser bigint,
fldNameUser NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablaghTakhfif decimal,
fldSharhTakhfif NVarchar(200) COLLATE Persian_100_CI_AS
)
delete #TempShow
delete #TempShowBank


update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')

insert into #TempShow(fldShomarePardakht,fldShomareSanad,fldCodeTafzili,fldSharhTafzili,
fldDate,fldCodeSandough,fldNameSandough,fldMablaghSandough,fldCodeBank,fldNameBank,
fldMablaghBank,fldMablaghCheck ,fldMablaghCheckVagozari,
fldMablaghKol,fldCodeUser,fldNameUser,fldMablaghTakhfif,fldSharhTakhfif)
select distinct dbo.tblPardakht.fldShomarePardakht,dbo.tblPardakht.fldShomareSanad,
dbo.tblPardakht.fldCodeTafzili,dbo.tblTafzili.fldSharheTafzili,
SUBSTRING(CONVERT(nvarchar,dbo.tblSodooreSanad.fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, dbo.tblSodooreSanad.fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, dbo.tblSodooreSanad.fldDate), 7, 2) AS fldDate
,NULL as fldCodeSandough,Null as fldNameSandough,0 as fldMablaghSandough,NULL as fldCodeBank,'' as fldNameBank
,0 as fldMablaghBank,0 as fldMablaghCheck,0 as fldMablaghCheckVagozari ,0 as fldMablaghKol
,NULL as fldCodeUser,'' as fldNameUser,0 as fldMablaghTakhfif,'' as fldSharhTakhfif
from tblPardakht
inner join dbo.tblTafzili on dbo.tblPardakht.fldCodeTafzili=dbo.tblTafzili.fldCodeTafzili
inner join dbo.tblSodooreSanad on dbo.tblPardakht.fldShomareSanad=dbo.tblSodooreSanad.fldSanad  and dbo.tblSodooreSanad.fldDate between @DateAz and @DateTa







		if @ListAshkhas<>''
		      begin
		       declare @StrDeleteAshkhas varchar(5000)
		        set  @StrDeleteAshkhas='delete from #TempShow 
		            where '+ @ListAshkhas + ''
					execute(@StrDeleteAshkhas)
		      end


			
	--select * from tblDaryaft
	--select * from tblSodooreSanad
	--select * from #TempShow
	--select * from #TempShowBank
	--------------------------Sandough-------------------------------------
			declare @strCodeKoleHesabSandough nvarchar(10)
	execute CodeKolHesab 'sandoogh',@strCodeKoleHesabSandough output

		UPDATE       #TempShow
		SET                fldCodeSandough = tblSodooreSanad.fldMoinKamel,				
						   fldMablaghSandough= tblSodooreSanad.fldBestankar				
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad 
								where tblSodooreSanad.fldCodeKol=@strCodeKoleHesabSandough


	
insert into #TempShowSandough(fldCodeSandough,fldNameSandough)


	select[fldCodeHesab], [fldSharheHesab] as fldNameBank from tblKolMoin
		where  fldCodeHesab like @strCodeKoleHesabSandough + '%' and len(fldCodeHesab)>len(@strCodeKoleHesabSandough)
		order by fldCodeHesab
				
		UPDATE       #TempShow
		SET                fldNameSandough = #TempShowSandough.fldNameSandough
																   			
		FROM           #TempShowSandough    INNER JOIN
								#TempShow  ON #TempShowSandough.fldCodeSandough=#TempShow.fldCodeSandough 
							
--------------------------------Bank----------------------------------------
			declare @strCodeKoleHesab nvarchar(10)
	execute CodeKolHesab 'bank',@strcodekolehesab output
		
			UPDATE       #TempShow
		SET                fldCodeBank = tblSodooreSanad.fldMoinKamel,
						  fldMablaghBank=tblSodooreSanad.fldBestankar											   			
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldCodeKol=@strcodekolehesab
								where tblSodooreSanad.fldCodeKol=@strcodekolehesab

 	

	insert into #TempShowBank(fldNameBank,fldCodeBank)
	select [fldSharheHesab],[fldCodeHesab] from tblKolMoin
		Where fldCodeHesab<>@strcodekolehesab and left(fldCodeHesab,len(@strcodekolehesab))=@strcodekolehesab
		order by fldCodeHesab
				
		UPDATE       #TempShow
		SET                fldNameBank = #TempShowBank.fldNameBank
																   			
		FROM           #TempShowBank    INNER JOIN
								#TempShow  ON #TempShowBank.fldCodeBank=#TempShow.fldCodeBank 
								
-----------------------------------Check-------------------------------------------
declare @strCodeKoleHesabCheack nvarchar(10)
	execute CodeKolHesab 'checkpardakhti',@strCodeKoleHesabCheack output
		
	insert into #TempShowCheck(fldShomarePardakht,fldMablaghCheck)
	select  #TempShow.fldShomarePardakht,tblSodooreSanad.fldBestankar from  tblSodooreSanad    INNER JOIN
		#TempShow  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheack
			where tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheack

			--select * from tblCheckeDaryafti


	UPDATE       #TempShow
		SET              
						  fldMablaghCheck=#TempShowCheck.fldMablaghCheck
		FROM           #TempShow   INNER JOIN
								#TempShowCheck  ON #TempShowCheck.fldShomarePardakht=#TempShow.fldShomarePardakht 
								where #TempShowCheck.fldShomarePardakht=#TempShow.fldShomarePardakht

-----------------------------------CheckVagozari-------------------------------------------
	declare @strCodeKoleHesabCheckVagozari nvarchar(10)
	execute CodeKolHesab 'check',@strCodeKoleHesabCheckVagozari output
	--select @strCodeKoleHesabCheckVagozari
	UPDATE       #TempShow
		SET              
						  fldMablaghCheckVagozari=tblSodooreSanad.fldBestankar									   			
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheckVagozari
								where tblSodooreSanad.fldCodeKol=@strCodeKoleHesabCheckVagozari
	


--------------------------------Takhfif----------------------------------	
declare @strCodeKoleHesabTakhfif nvarchar(10)
	execute CodeMoinHesab'takhfifatepardakht',@strCodeKoleHesabTakhfif output
	
	UPDATE       #TempShow
		SET              
						  fldMablaghTakhfif=tblSodooreSanad.fldBestankar,
						  fldSharhTakhfif=tblSodooreSanad.fldSharh
						  							   			
		FROM           #TempShow   INNER JOIN
								tblSodooreSanad  ON tblSodooreSanad.fldSanad=#TempShow.fldShomareSanad and tblSodooreSanad.fldMoinKamel=@strCodeKoleHesabTakhfif
								where tblSodooreSanad.fldMoinKamel=@strCodeKoleHesabTakhfif

-----------------------------Karbar-------------------------------------


delete #TempShowUser1
delete #TempShowUser2



insert into #TempShowUser1(id,fldShomarePardakht)
SELECT         MAX(id) AS id ,fldShomare
FROM            tblAmalkardekarbar 
WHERE        (fldNameForm = 'پرداخت') AND (NoeAmaliat = 'جدید')
GROUP BY fldShomare
ORDER BY fldShomare

insert into #TempShowUser2(id,fldShomarePardakht)
SELECT         MAX(id) AS id ,fldShomare
FROM            tblAmalkardekarbar 
WHERE        (fldNameForm = 'پرداخت') AND (NoeAmaliat = 'ویرایش')
GROUP BY fldShomare
ORDER BY fldShomare

insert into #TempShowUser1(id,fldShomarePardakht)
select id,fldShomarePardakht from #TempShowUser2 where fldShomarePardakht not in(select fldShomarePardakht from #TempShowUser1)

update #TempShowUser1 Set 
	fldCodeUser=tblAmalkardekarbar.fldCodeKarbar,
	fldNameUser=tblAmalkardekarbar.fldNameKarbar					  							   			
		FROM           #TempShowUser1   INNER JOIN
								tblAmalkardekarbar  ON tblAmalkardekarbar.fldShomare=#TempShowUser1.fldShomarePardakht
								where tblAmalkardekarbar.id=#TempShowUser1.id


update #TempShow Set 
	fldCodeUser=#TempShowUser1.fldCodeUser,
	fldNameUser=#TempShowUser1.fldNameUser
						  							   			
		FROM           #TempShow   INNER JOIN
								#TempShowUser1  ON #TempShowUser1.fldShomarePardakht=#TempShow.fldShomarePardakht  


  	  if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end
-----------------------------fldMablaghKol----------------------------------------
declare @SumMablaghKol decimal


UPDATE       #TempShow
		SET              
						  fldMablaghKol=(#TempShow.fldMablaghSandough+#TempShow.fldMablaghBank+#TempShow.fldMablaghCheck-#TempShow.fldMablaghTakhfif)
						  
						  							   			
		FROM           #TempShow


-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################
delete from #TempShow where fldCodeTafzili not in (select code from @accessCodes)
-- ##########################################################

-----------------------------------------------------------------------------------------------------------------------------------------------
SELECT  ROW_NUMBER() OVER(ORDER BY fldShomarePardakht) as fldRadif,fldShomarePardakht,fldShomareSanad,fldCodeTafzili,fldSharhTafzili,fldDate  
,fldCodeSandough,fldNameSandough,fldMablaghSandough,fldCodeBank,fldNameBank,
fldMablaghBank,fldMablaghCheck ,fldMablaghCheckVagozari,
fldMablaghKol,fldCodeUser,fldNameUser,fldMablaghTakhfif,fldSharhTakhfif
FROM #TempShow  where 
fldMablaghSandough between CONVERT(nvarchar(50),@MablaghAzNaghd) and CONVERT(nvarchar(50),@MablaghTaNaghd) and 
fldMablaghBank between  CONVERT(nvarchar(50),@MablaghAzBank)  and CONVERT(nvarchar(50),@MablaghTaBank) and 
fldMablaghCheck between  CONVERT(nvarchar(50),@MablaghAzCheck)  and CONVERT(nvarchar(50),@MablaghTaCheck) and 
fldMablaghTakhfif between  CONVERT(nvarchar(50),@MablaghAzTakhfif)  and CONVERT(nvarchar(50),@MablaghTaTakhfif) and 
fldMablaghKol between  CONVERT(nvarchar(50),@MablaghAzKol)  and CONVERT(nvarchar(50),@MablaghTaKol)



END
GO

-- ===============================================
-- SP: [dbo].[z166UpdateRowColor]
-- ===============================================
IF OBJECT_ID(N'dbo.z166UpdateRowColor', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z166UpdateRowColor] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z166UpdateRowColor]
@Id bigint,
@CodeColor int,
@FormName Nvarchar(20)


as 

begin
Update tblSodooreSanad Set fldColorBank=@CodeColor where ID=@Id
	if @FormName='Bank'
	begin
	Update tblSodooreSanad Set fldColorBank=@CodeColor where ID=@Id

	end
	else if @FormName='Sandoogh'
	begin
	Update tblSodooreSanad Set fldColorSandoogh=@CodeColor where ID=@Id

	end
	else if @FormName='SooratHesab'
	begin
	Update tblSodooreSanad Set fldColorSooratHesab=@CodeColor where ID=@Id

	end
end
GO

-- ===============================================
-- SP: [dbo].[z167ShowList_ReportFactorKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.z167ShowList_ReportFactorKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z167ShowList_ReportFactorKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z167ShowList_ReportFactorKharid]
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@DateFactorAz varchar(50),
	@DateFactorTa varchar(50),
	@MablaghAz decimal, 
	@MablaghTa decimal
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 

 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)
 create table #TempListDateTimeSabtFactor(
fldShomareFactor bigint,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS
)

 create table #TempListDateFactor(
fldShomareFactor bigint,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS
)

 create table #TempSumKharid(
fldShomareFactor bigint,
fldMablaghKharid decimal,
fldCodeAnbar bigint

)

create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
fldShomareFactorKharid bigint,
fldLock nvarchar(5)
)


	delete from #TempSumKharid
	delete from #TempListDateTimeSabtFactor
	delete from #TempShow
	delete from #TempListCodeAnbar

update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizeKharid where fldRadif=1)

insert into #TempSumKharid(fldShomareFactor,fldMablaghKharid,fldCodeAnbar)
			(select tblRizeKharid.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizeKharid  group by fldShomareFactor )

--select * from #TempListCodeAnbar
insert into #TempListDateTimeSabtFactor(fldShomareFactor,fldTimeSabtFactor,fldDateSabtFactor,fldNameKarbar)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldNameKarbar from tblAmalkardekarbar where fldNameForm=N'خرید' and NoeAmaliat=N'جدید' )
			--select * from #TempListDateTimeSabtFactor

insert into #TempListDateFactor(fldShomareFactor,fldDateFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizeKharid )
			--select * from tblRizeForoosh

		
			--select * from #TempListDateFactor
		--select * from #TempSumKharid
update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumKharid as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeAnbar,fldNameAnbar,fldNameKarbar,fldLock)
 select DISTINCT  tblRizeKharid.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,'' as fldDateFactor,
						'' as fldTimeFacttor,'' as fldDateFacttor,#TempSumKharid.fldCodeAnbar,'' as fldNameAnbar,'' as fldNameKarbar,tblKharid.fldLock
							  
 from tblRizeKharid 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizeKharid.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumKharid on #TempSumKharid.fldShomareFactor=tblRizeKharid.fldShomareFactor
 inner join tblKharid on tblKharid.fldShomareFactorKharid=tblRizeKharid.fldShomareFactor




							--SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDateShow

	update R Set R.fldMablagh=(#TempSumKharid.fldMablaghKharid)
								from #TempShow as R 
								inner join #TempSumKharid on R.fldShomareFactor=#TempSumKharid.fldShomareFactor						
	
	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode
									
									
	update R Set R.fldTimeSabtFactor=(#TempListDateTimeSabtFactor.fldTimeSabtFactor),R.fldDateSabtFactor=(#TempListDateTimeSabtFactor.fldDateSabtFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor
	
		update R Set R.fldNameKarbar=(#TempListDateTimeSabtFactor.fldNameKarbar)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor

	update R Set R.fldDateFactor=(#TempListDateFactor.fldDateFactor)
								from #TempShow as R 
								inner join #TempListDateFactor on R.fldShomareFactor=#TempListDateFactor.fldShomareFactor

	update #TempShow set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempShow.fldCodetafzili=tbl5.fldCodeTafzili

	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end



	 if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end

	--insert into #tempPishFactor
	--	(fldShomareFactorForoosh,fldShomarepishfactor)
	--Select  fldShomareFactorForoosh,fldShomarepishfactor from tblForoosh Where (isnumeric(fldShomarePishFactor) = 1) and fldShomarePishFactor<>0

	--delete from #TempShow 
	--	 where fldCodeTafzili NOT Like '10000 %'
	--update #TempShow set fldShomareFactorForoosh=#tempPishFactor.fldShomareFactorForoosh from #tempPishFactor Where #TempShow.fldShomareFactor=#tempPishFactor.fldShomarePishFactor
	
	--update #TempShow set fldShomarePishfactor =tblForoosh.fldShomarePishFactor from tblForoosh Where 
SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeAnbar,fldNameAnbar,fldNameKarbar,fldShomareTell
,fldLock FROM  #TempShow where 
fldMablagh between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

END
GO

-- ===============================================
-- SP: [dbo].[z167ShowList_ReportFactorKharid_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z167ShowList_ReportFactorKharid_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z167ShowList_ReportFactorKharid_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z167ShowList_ReportFactorKharid_WithUserCode]
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@DateFactorAz varchar(50),
	@DateFactorTa varchar(50),
	@MablaghAz decimal, 
	@MablaghTa decimal,
	@UserCode bigint
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 

 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)
 create table #TempListDateTimeSabtFactor(
fldShomareFactor bigint,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS
)

 create table #TempListDateFactor(
fldShomareFactor bigint,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS
)

 create table #TempSumKharid(
fldShomareFactor bigint,
fldMablaghKharid decimal,
fldCodeAnbar bigint

)

create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(200) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDateFactor  Nvarchar(200) collate Persian_100_CI_AS,
fldTimeSabtFactor  Nvarchar(200) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(200) collate Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
fldShomareFactorKharid bigint,
fldLock nvarchar(10)
)


	delete from #TempSumKharid
	delete from #TempListDateTimeSabtFactor
	delete from #TempShow
	delete from #TempListCodeAnbar

update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizeKharid where fldRadif=1)

insert into #TempSumKharid(fldShomareFactor,fldMablaghKharid,fldCodeAnbar)
			(select tblRizeKharid.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizeKharid  group by fldShomareFactor )

--select * from #TempListCodeAnbar
insert into #TempListDateTimeSabtFactor(fldShomareFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeKarbar,fldNameKarbar)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldCodeKarbar,fldNameKarbar from tblAmalkardekarbar where fldNameForm=N'خرید' and NoeAmaliat=N'جدید' )
			--select * from #TempListDateTimeSabtFactor

insert into #TempListDateFactor(fldShomareFactor,fldDateFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizeKharid )
			--select * from tblRizeForoosh

		
			--select * from #TempListDateFactor
		--select * from #TempSumKharid
update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumKharid as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeAnbar,fldNameAnbar,fldCodeKarbar,fldNameKarbar,fldLock)
 select DISTINCT  tblRizeKharid.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,'' as fldDateFactor,
						'' as fldTimeFacttor,'' as fldDateFacttor,#TempSumKharid.fldCodeAnbar,'' as fldNameAnbar,0 as fldCodeKarbar,'' as fldNameKarbar,tblKharid.fldLock
							  
 from tblRizeKharid 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizeKharid.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumKharid on #TempSumKharid.fldShomareFactor=tblRizeKharid.fldShomareFactor
 inner join tblKharid on tblKharid.fldShomareFactorKharid=tblRizeKharid.fldShomareFactor




							--SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDateShow

	update R Set R.fldMablagh=(#TempSumKharid.fldMablaghKharid)
								from #TempShow as R 
								inner join #TempSumKharid on R.fldShomareFactor=#TempSumKharid.fldShomareFactor						
	
	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode
									
									
	update R Set R.fldTimeSabtFactor=(#TempListDateTimeSabtFactor.fldTimeSabtFactor),R.fldDateSabtFactor=(#TempListDateTimeSabtFactor.fldDateSabtFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor
	
		update R Set R.fldNameKarbar=(#TempListDateTimeSabtFactor.fldNameKarbar),R.fldCodeKarbar=(#TempListDateTimeSabtFactor.fldCodeKarbar)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor

	update R Set R.fldDateFactor=(#TempListDateFactor.fldDateFactor)
								from #TempShow as R 
								inner join #TempListDateFactor on R.fldShomareFactor=#TempListDateFactor.fldShomareFactor

	update #TempShow set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempShow.fldCodetafzili=tbl5.fldCodeTafzili

	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end



	 if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end

	--insert into #tempPishFactor
	--	(fldShomareFactorForoosh,fldShomarepishfactor)
	--Select  fldShomareFactorForoosh,fldShomarepishfactor from tblForoosh Where (isnumeric(fldShomarePishFactor) = 1) and fldShomarePishFactor<>0

	--delete from #TempShow 
	--	 where fldCodeTafzili NOT Like '10000 %'
	--update #TempShow set fldShomareFactorForoosh=#tempPishFactor.fldShomareFactorForoosh from #tempPishFactor Where #TempShow.fldShomareFactor=#tempPishFactor.fldShomarePishFactor
	
	--update #TempShow set fldShomarePishfactor =tblForoosh.fldShomarePishFactor from tblForoosh Where 

-- ########################################################
-- Group Ashkhas Limitation
-- ########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ########################################################

SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeAnbar,fldNameAnbar,fldCodeKarbar,fldNameKarbar,fldShomareTell
,fldLock FROM  #TempShow where 
fldCodeTafzili in (select code from @accessCodes) and
fldMablagh between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

END
GO

-- ===============================================
-- SP: [dbo].[z168ShowList_ReportFactorBargashtAzKharid]
-- ===============================================
IF OBJECT_ID(N'dbo.z168ShowList_ReportFactorBargashtAzKharid', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z168ShowList_ReportFactorBargashtAzKharid] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z168ShowList_ReportFactorBargashtAzKharid]
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@DateFactorAz varchar(50),
	@DateFactorTa varchar(50),
	@MablaghAz decimal, 
	@MablaghTa decimal
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 

 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)
 create table #TempListDateTimeSabtFactor(
fldShomareFactor bigint,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS
)

 create table #TempListDateFactor(
fldShomareFactor bigint,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS
)

 create table #TempSumKharid(
fldShomareFactor bigint,
fldMablaghKharid decimal,
fldCodeAnbar bigint

)

create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
fldShomareFactorKharid bigint,
fldLock nvarchar(5)
)


	delete from #TempSumKharid
	delete from #TempListDateTimeSabtFactor
	delete from #TempShow
	delete from #TempListCodeAnbar

update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizeKharid where fldRadif=1)

insert into #TempSumKharid(fldShomareFactor,fldMablaghKharid,fldCodeAnbar)
			(select tblRizeBargashtAzKharid.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizeBargashtAzKharid  group by fldShomareFactor )

--select * from #TempListCodeAnbar
insert into #TempListDateTimeSabtFactor(fldShomareFactor,fldTimeSabtFactor,fldDateSabtFactor,fldNameKarbar)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldNameKarbar from tblAmalkardekarbar where fldNameForm=N'برگشت از خرید' and NoeAmaliat=N'جدید' )
			
	--		select * from tblAmalkardekarbar

insert into #TempListDateFactor(fldShomareFactor,fldDateFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizeBargashtAzKharid )
			--select * from tblRizeForoosh

		
			--select * from #TempListDateFactor
		--select * from #TempSumKharid
update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumKharid as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeAnbar,fldNameAnbar,fldNameKarbar,fldLock)
 select DISTINCT  tblRizeBargashtAzKharid.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,'' as fldDateFactor,
						'' as fldTimeFacttor,'' as fldDateFacttor,#TempSumKharid.fldCodeAnbar,'' as fldNameAnbar,'' as fldNameKarbar,tblBargashtAzKharid.fldLock						  
 from tblRizeBargashtAzKharid 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizeBargashtAzKharid.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumKharid on #TempSumKharid.fldShomareFactor=tblRizeBargashtAzKharid.fldShomareFactor
 inner join tblBargashtAzKharid on tblBargashtAzKharid.fldShomareFactorKharid=tblRizeBargashtAzKharid.fldShomareFactor




							--SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDateShow

	update R Set R.fldMablagh=(#TempSumKharid.fldMablaghKharid)
								from #TempShow as R 
								inner join #TempSumKharid on R.fldShomareFactor=#TempSumKharid.fldShomareFactor						
	
	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode
									
									
	update R Set R.fldTimeSabtFactor=(#TempListDateTimeSabtFactor.fldTimeSabtFactor),R.fldDateSabtFactor=(#TempListDateTimeSabtFactor.fldDateSabtFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor
	
		update R Set R.fldNameKarbar=(#TempListDateTimeSabtFactor.fldNameKarbar)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor

	update R Set R.fldDateFactor=(#TempListDateFactor.fldDateFactor)
								from #TempShow as R 
								inner join #TempListDateFactor on R.fldShomareFactor=#TempListDateFactor.fldShomareFactor

	update #TempShow set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempShow.fldCodetafzili=tbl5.fldCodeTafzili

	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end



	 if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end

	--insert into #tempPishFactor
	--	(fldShomareFactorForoosh,fldShomarepishfactor)
	--Select  fldShomareFactorForoosh,fldShomarepishfactor from tblForoosh Where (isnumeric(fldShomarePishFactor) = 1) and fldShomarePishFactor<>0

	--delete from #TempShow 
	--	 where fldCodeTafzili NOT Like '10000 %'
	--update #TempShow set fldShomareFactorForoosh=#tempPishFactor.fldShomareFactorForoosh from #tempPishFactor Where #TempShow.fldShomareFactor=#tempPishFactor.fldShomarePishFactor
	
	--update #TempShow set fldShomarePishfactor =tblForoosh.fldShomarePishFactor from tblForoosh Where 
SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeAnbar,fldNameAnbar,fldNameKarbar,fldShomareTell
,fldLock FROM  #TempShow where 
fldMablagh between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

END
GO

-- ===============================================
-- SP: [dbo].[z168ShowList_ReportFactorBargashtAzKharid_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z168ShowList_ReportFactorBargashtAzKharid_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z168ShowList_ReportFactorBargashtAzKharid_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z168ShowList_ReportFactorBargashtAzKharid_WithUserCode]
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@DateFactorAz varchar(50),
	@DateFactorTa varchar(50),
	@MablaghAz decimal, 
	@MablaghTa decimal,
	@userCode bigint
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 

 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)
 create table #TempListDateTimeSabtFactor(
fldShomareFactor bigint,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS
)

 create table #TempListDateFactor(
fldShomareFactor bigint,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS
)

 create table #TempSumKharid(
fldShomareFactor bigint,
fldMablaghKharid decimal,
fldCodeAnbar bigint

)

create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(200) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDateFactor  Nvarchar(200) collate Persian_100_CI_AS,
fldTimeSabtFactor  Nvarchar(200) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(200) collate Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
fldShomareFactorKharid bigint,
fldLock nvarchar(10)
)


	delete from #TempSumKharid
	delete from #TempListDateTimeSabtFactor
	delete from #TempShow
	delete from #TempListCodeAnbar

update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizeKharid where fldRadif=1)

insert into #TempSumKharid(fldShomareFactor,fldMablaghKharid,fldCodeAnbar)
			(select tblRizeBargashtAzKharid.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizeBargashtAzKharid  group by fldShomareFactor )

--select * from #TempListCodeAnbar
insert into #TempListDateTimeSabtFactor(fldShomareFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeKarbar,fldNameKarbar)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldCodeKarbar,fldNameKarbar from tblAmalkardekarbar where fldNameForm=N'برگشت از خرید' and NoeAmaliat=N'جدید' )
			
	--		select * from tblAmalkardekarbar

insert into #TempListDateFactor(fldShomareFactor,fldDateFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizeBargashtAzKharid )
			--select * from tblRizeForoosh

		
			--select * from #TempListDateFactor
		--select * from #TempSumKharid
update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumKharid as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeAnbar,fldNameAnbar,fldCodeKarbar,fldNameKarbar,fldLock)
 select DISTINCT  tblRizeBargashtAzKharid.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,'' as fldDateFactor,
						'' as fldTimeFacttor,'' as fldDateFacttor,#TempSumKharid.fldCodeAnbar,'' as fldNameAnbar,0 as fldCodeKarbar,'' as fldNameKarbar,tblBargashtAzKharid.fldLock						  
 from tblRizeBargashtAzKharid 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizeBargashtAzKharid.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumKharid on #TempSumKharid.fldShomareFactor=tblRizeBargashtAzKharid.fldShomareFactor
 inner join tblBargashtAzKharid on tblBargashtAzKharid.fldShomareFactorKharid=tblRizeBargashtAzKharid.fldShomareFactor




							--SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDateShow

	update R Set R.fldMablagh=(#TempSumKharid.fldMablaghKharid)
								from #TempShow as R 
								inner join #TempSumKharid on R.fldShomareFactor=#TempSumKharid.fldShomareFactor						
	
	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode
									
									
	update R Set R.fldTimeSabtFactor=(#TempListDateTimeSabtFactor.fldTimeSabtFactor),R.fldDateSabtFactor=(#TempListDateTimeSabtFactor.fldDateSabtFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor
	
		update R Set R.fldNameKarbar=(#TempListDateTimeSabtFactor.fldNameKarbar),R.fldCodeKarbar=(#TempListDateTimeSabtFactor.fldCodeKarbar)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor

	update R Set R.fldDateFactor=(#TempListDateFactor.fldDateFactor)
								from #TempShow as R 
								inner join #TempListDateFactor on R.fldShomareFactor=#TempListDateFactor.fldShomareFactor

	update #TempShow set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempShow.fldCodetafzili=tbl5.fldCodeTafzili

	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end



	 if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end

	--insert into #tempPishFactor
	--	(fldShomareFactorForoosh,fldShomarepishfactor)
	--Select  fldShomareFactorForoosh,fldShomarepishfactor from tblForoosh Where (isnumeric(fldShomarePishFactor) = 1) and fldShomarePishFactor<>0

	--delete from #TempShow 
	--	 where fldCodeTafzili NOT Like '10000 %'
	--update #TempShow set fldShomareFactorForoosh=#tempPishFactor.fldShomareFactorForoosh from #tempPishFactor Where #TempShow.fldShomareFactor=#tempPishFactor.fldShomarePishFactor
	
	--update #TempShow set fldShomarePishfactor =tblForoosh.fldShomarePishFactor from tblForoosh Where 
-- ######################################################################
-- ###################### Group Ashkhas Limitation
-- ######################################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ######################################################################

SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeAnbar,fldNameAnbar,fldCodeKarbar,fldNameKarbar,fldShomareTell
,fldLock FROM  #TempShow where 
fldCodeTafzili in (select code from @accessCodes) and
fldMablagh between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

END
GO

-- ===============================================
-- SP: [dbo].[z169ShowList_ReportFactorForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.z169ShowList_ReportFactorForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z169ShowList_ReportFactorForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z169ShowList_ReportFactorForoosh]
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@ListVisitor varchar(5000)=null,
	@MablaghAz decimal, 
	@MablaghTa decimal
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 
 create table #TempSumForoosh(
fldShomareFactor bigint,
fldMablaghForoosh decimal,
fldCodeAnbar bigint

)
 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)
 create table #TempListDateTimeSabtFactor(
fldShomareFactor bigint,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS
)

 create table #TempListDateFactor(
fldShomareFactor bigint,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS

)


create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeVisitor bigint,
fldNameVisitor NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
fldShomareFactorForoosh bigint,
fldLock nvarchar(5)
)



	delete from #TempListDateTimeSabtFactor
	delete from #TempShow
	delete from #TempListCodeAnbar
	delete from #TempSumForoosh

update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizeForoosh where fldRadif=1)

insert into #TempSumForoosh(fldShomareFactor,fldMablaghForoosh,fldCodeAnbar)
			(select tblRizeForoosh.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizeForoosh  group by fldShomareFactor )


insert into #TempListDateTimeSabtFactor(fldShomareFactor,fldTimeSabtFactor,fldDateSabtFactor,fldNameKarbar)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldNameKarbar from tblAmalkardekarbar where fldNameForm='فروش' and NoeAmaliat=N'جدید' )
			
			--select * from #TempListCodeAnbar
			--select * from #TempSumForoosh
			--select * from #TempListDateTimeSabtFactor
			--select * from #TempListDateFactor

insert into #TempListDateFactor(fldShomareFactor,fldDateFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizeForoosh )
			--select * from tblRizeForoosh

update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumForoosh as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldNameKarbar,fldLock)
 select DISTINCT  tblRizeForoosh.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,'' as fldDateFactor,
						'' as fldTimeFacttor,'' as fldDateFacttor,
					tblRizeForoosh.fldCodeVasete ,''as fldNameVisitor,#TempSumForoosh.fldCodeAnbar,'' as fldNameAnbar,'' as fldNameKarbar,tblForoosh.fldLock
							  
 from tblRizeForoosh 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizeForoosh.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumForoosh on #TempSumForoosh.fldShomareFactor=tblRizeForoosh.fldShomareFactor
 inner join tblForoosh on #TempSumForoosh.fldShomareFactor=tblForoosh.fldShomareFactorForoosh




							--SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDateShow

	update R Set R.fldMablagh=(#TempSumForoosh.fldMablaghForoosh)
								from #TempShow as R 
								inner join #TempSumForoosh on R.fldShomareFactor=#TempSumForoosh.fldShomareFactor						
	update R Set R.fldNameVisitor=(viewLoadVizitor.fldSharheTafzili)
								from #TempShow as R 
								inner join viewLoadVizitor on R.fldCodeVisitor=viewLoadVizitor.fldCodeTafzili						

	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode
									
	update R Set R.fldTimeSabtFactor=(#TempListDateTimeSabtFactor.fldTimeSabtFactor),R.fldDateSabtFactor=(#TempListDateTimeSabtFactor.fldDateSabtFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor
	

	update R Set R.fldNameKarbar=(#TempListDateTimeSabtFactor.fldNameKarbar)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor

	update R Set R.fldDateFactor=(#TempListDateFactor.fldDateFactor)
								from #TempShow as R 
								inner join #TempListDateFactor on R.fldShomareFactor=#TempListDateFactor.fldShomareFactor

	update #TempShow set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempShow.fldCodetafzili=tbl5.fldCodeTafzili

	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end

	if @ListVisitor <>''
		      begin
		       declare @StrDeleteVisitor varchar(5000)
		        set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListVisitor + ''
					execute(@StrDeleteVisitor)
		      end

	 if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end

	--insert into #tempFactor
	--	(fldShomareFactorForoosh)
	--Select  fldShomareFactorForoosh from tblForoosh Where (isnumeric(fldShomareFactor) = 1) and fldShomareFactor<>0


	--update #TempShow set fldShomareFactorForoosh=#tempPishFactor.fldShomareFactorForoosh from #tempPishFactor Where #TempShow.fldShomareFactor=#tempPishFactor.fldShomarePishFactor
	
	--update #TempShow set fldShomarePishfactor =tblForoosh.fldShomarePishFactor from tblForoosh Where 
SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldNameKarbar,fldShomareTell  
,fldLock FROM  #TempShow where 
fldMablagh between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

END
GO

-- ===============================================
-- SP: [dbo].[z169ShowList_ReportFactorForoosh_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z169ShowList_ReportFactorForoosh_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z169ShowList_ReportFactorForoosh_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z169ShowList_ReportFactorForoosh_WithUserCode]
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@ListVisitor varchar(5000)=null,
	@ListFeeDynamic varchar(5000)=null,
	@MablaghAz decimal(18, 4), 
	@MablaghTa decimal(18, 4),
	@userCode bigint
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;


	--declare @ListAshkhas varchar(5000)=null
	--declare @ListGroupAshkhas varchar(5000)=null
	--declare @ListKarbaran varchar(5000)=null
	--declare @ListAnbar varchar(5000)=null
	--declare @ListVisitor varchar(5000)=null
	--declare @ListFeeDynamic varchar(5000)=null
	--declare @MablaghAz decimal(18, 4) = 0
	--declare @MablaghTa decimal(18, 4) = 9000000000
	--declare @userCode bigint = 1000
 
 create table #TempSumForoosh(
fldShomareFactor bigint,
fldMablaghForoosh decimal(18, 4),
fldCodeAnbar bigint

)
 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)
 create table #TempListDateTimeSabtFactor(
fldShomareFactor bigint,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS
)

 create table #TempListDateFactor(
fldShomareFactor bigint,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS

)


create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(150) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(150) COLLATE Persian_100_CI_AS,
fldMablagh decimal(18, 4),
fldDateFactor  Nvarchar(50) collate Persian_100_CI_AS,
fldTimeSabtFactor  Nvarchar(50) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(50) collate Persian_100_CI_AS,
fldCodeVisitor bigint,
fldNameVisitor NVarchar(150) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(150) COLLATE Persian_100_CI_AS,
fldCodeFeeDynamic bigint,
fldNameFeeDynamic NVarchar(150) COLLATE Persian_100_CI_AS,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(150) COLLATE Persian_100_CI_AS,
fldShomareTell nvarchar(50) COLLATE Persian_100_CI_AS,
fldShomareFactorForoosh bigint,
fldLock nvarchar(15)
)



	delete from #TempListDateTimeSabtFactor
	delete from #TempShow
	delete from #TempListCodeAnbar
	delete from #TempSumForoosh

update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizeForoosh where fldRadif=1)

insert into #TempSumForoosh(fldShomareFactor,fldMablaghForoosh,fldCodeAnbar)
			(select tblRizeForoosh.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizeForoosh  group by fldShomareFactor )


insert into #TempListDateTimeSabtFactor(fldShomareFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeKarbar,fldNameKarbar)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldCodeKarbar,fldNameKarbar from tblAmalkardekarbar where fldNameForm='فروش' and NoeAmaliat=N'جدید' )
			
			--select * from #TempListCodeAnbar
			--select * from #TempSumForoosh
			--select * from #TempListDateTimeSabtFactor
			--select * from #TempListDateFactor

insert into #TempListDateFactor(fldShomareFactor,fldDateFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizeForoosh )
			

update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumForoosh as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldCodeFeeDynamic,fldNameFeeDynamic,fldCodeKarbar,fldNameKarbar,fldLock)
 select DISTINCT  tblRizeForoosh.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,'' as fldDateFactor,
						'' as fldTimeFacttor,'' as fldDateFacttor,
					tblRizeForoosh.fldCodeVasete ,''as fldNameVisitor,#TempSumForoosh.fldCodeAnbar,'' as fldNameAnbar,tblForoosh.fldCodeFeeDynamic,'' as fldNameFeeDynamic,0 as fldCodeKarbar,'' as fldNameKarbar,tblForoosh.fldLock
							  
 from tblRizeForoosh 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizeForoosh.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumForoosh on #TempSumForoosh.fldShomareFactor=tblRizeForoosh.fldShomareFactor
 inner join tblForoosh on #TempSumForoosh.fldShomareFactor=tblForoosh.fldShomareFactorForoosh


	

							--SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDateShow

	update R Set R.fldMablagh=(#TempSumForoosh.fldMablaghForoosh)
								from #TempShow as R 
								inner join #TempSumForoosh on R.fldShomareFactor=#TempSumForoosh.fldShomareFactor						
	update R Set R.fldNameVisitor=(viewLoadVizitor.fldSharheTafzili)
								from #TempShow as R 
								inner join viewLoadVizitor on R.fldCodeVisitor=viewLoadVizitor.fldCodeTafzili						

	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode
									
	update R Set R.fldTimeSabtFactor=(#TempListDateTimeSabtFactor.fldTimeSabtFactor),R.fldDateSabtFactor=(#TempListDateTimeSabtFactor.fldDateSabtFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor
	

	update R Set R.fldNameKarbar=(#TempListDateTimeSabtFactor.fldNameKarbar),R.fldCodeKarbar=(#TempListDateTimeSabtFactor.fldCodeKarbar)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor

	update R Set R.fldDateFactor=(#TempListDateFactor.fldDateFactor)
								from #TempShow as R 
								inner join #TempListDateFactor on R.fldShomareFactor=#TempListDateFactor.fldShomareFactor

	update #TempShow set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempShow.fldCodetafzili=tbl5.fldCodeTafzili

	update R Set R.fldNameFeeDynamic=(tblSharheFeeDynamic.fldSharh)
								from #TempShow as R 
								inner join tblSharheFeeDynamic on R.fldCodeFeeDynamic=tblSharheFeeDynamic.fldCodeSharh
	

	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end

	if @ListVisitor <>''
		      begin
		       declare @StrDeleteVisitor varchar(5000)
		        set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListVisitor + ''
					execute(@StrDeleteVisitor)
		      end

	 if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end
			  	if @ListFeeDynamic <>''
		      begin
		       declare @StrDeleteFeeDynamic varchar(5000)
		        set  @StrDeleteFeeDynamic='delete from #TempShow 
		            where '+ @ListFeeDynamic + ''
					execute(@StrDeleteFeeDynamic)
		      end

	--insert into #tempFactor
	--	(fldShomareFactorForoosh)
	--Select  fldShomareFactorForoosh from tblForoosh Where (isnumeric(fldShomareFactor) = 1) and fldShomareFactor<>0


	--update #TempShow set fldShomareFactorForoosh=#tempPishFactor.fldShomareFactorForoosh from #tempPishFactor Where #TempShow.fldShomareFactor=#tempPishFactor.fldShomarePishFactor
	
	--update #TempShow set fldShomarePishfactor =tblForoosh.fldShomarePishFactor from tblForoosh Where 

-- ##########################################
declare @accessCodesTafzili table(code bigint)
insert into @accessCodesTafzili select * from ZF_GetAccessableAshkhasCode(@userCode) 

-- ##########################################
SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldNameFeeDynamic,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldCodeKarbar,fldNameKarbar,fldShomareTell  
,fldLock FROM  #TempShow where 
fldCodeTafzili in (select code from @accessCodesTafzili ) and
fldMablagh between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

END
GO

-- ===============================================
-- SP: [dbo].[z170ShowList_ReportfactorBargashtAzForoosh]
-- ===============================================
IF OBJECT_ID(N'dbo.z170ShowList_ReportfactorBargashtAzForoosh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z170ShowList_ReportfactorBargashtAzForoosh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z170ShowList_ReportfactorBargashtAzForoosh]
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@ListVisitor varchar(5000)=null,
	@MablaghAz decimal, 
	@MablaghTa decimal
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 
 create table #TempSumForoosh(
fldShomareFactor bigint,
fldMablaghForoosh decimal,
fldCodeAnbar bigint

)
 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)
 create table #TempListDateTimeSabtFactor(
fldShomareFactor bigint,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS
)

 create table #TempListDateFactor(
fldShomareFactor bigint,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS
)


create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeVisitor bigint,
fldNameVisitor NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
fldShomareFactorForoosh bigint,
fldLock nvarchar(5)
)



	delete from #TempListDateTimeSabtFactor
	delete from #TempShow
	delete from #TempListCodeAnbar
	delete from #TempSumForoosh

update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizeBargashtAzForoosh where fldRadif=1)

insert into #TempSumForoosh(fldShomareFactor,fldMablaghForoosh,fldCodeAnbar)
			(select tblRizeBargashtAzForoosh.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizeBargashtAzForoosh  group by fldShomareFactor )


insert into #TempListDateTimeSabtFactor(fldShomareFactor,fldTimeSabtFactor,fldDateSabtFactor,fldNameKarbar)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldNameKarbar from tblAmalkardekarbar where fldNameForm='برگشت از فروش' and NoeAmaliat=N'جدید' )
			
			--select * from #TempListCodeAnbar
			--select * from #TempSumForoosh
			--select * from #TempListDateTimeSabtFactor
			--select * from #TempListDateFactor

insert into #TempListDateFactor(fldShomareFactor,fldDateFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizeBargashtAzForoosh)
			--select * from tblRizeBargashtAzForoosh

update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumForoosh as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldNameKarbar,fldLock)
 select DISTINCT  tblRizeBargashtAzForoosh.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,'' as fldDateFactor,
						'' as fldTimeFacttor,'' as fldDateFacttor,
					tblRizeBargashtAzForoosh.fldCodeVasete ,''as fldNameVisitor,#TempSumForoosh.fldCodeAnbar,'' as fldNameAnbar,'' as fldNameKarbar,tblBargashtAzForoosh.fldLock
							  
 from tblRizeBargashtAzForoosh 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizeBargashtAzForoosh.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumForoosh on #TempSumForoosh.fldShomareFactor=tblRizeBargashtAzForoosh.fldShomareFactor
 inner join tblForoosh on #TempSumForoosh.fldShomareFactor=tblForoosh.fldShomareFactorForoosh
 inner join tblBargashtAzForoosh on tblRizeBargashtAzForoosh.fldShomareFactor=tblBargashtAzForoosh.fldShomareFactorForoosh



							--SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDateShow

	update R Set R.fldMablagh=(#TempSumForoosh.fldMablaghForoosh)
								from #TempShow as R 
								inner join #TempSumForoosh on R.fldShomareFactor=#TempSumForoosh.fldShomareFactor						
	update R Set R.fldNameVisitor=(viewLoadVizitor.fldSharheTafzili)
								from #TempShow as R 
								inner join viewLoadVizitor on R.fldCodeVisitor=viewLoadVizitor.fldCodeTafzili						

	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode
									
	update R Set R.fldTimeSabtFactor=(#TempListDateTimeSabtFactor.fldTimeSabtFactor),R.fldDateSabtFactor=(#TempListDateTimeSabtFactor.fldDateSabtFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor
	

	update R Set R.fldNameKarbar=(#TempListDateTimeSabtFactor.fldNameKarbar)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor

	update R Set R.fldDateFactor=(#TempListDateFactor.fldDateFactor)
								from #TempShow as R 
								inner join #TempListDateFactor on R.fldShomareFactor=#TempListDateFactor.fldShomareFactor

	update #TempShow set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempShow.fldCodetafzili=tbl5.fldCodeTafzili

	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end

	if @ListVisitor <>''
		      begin
		       declare @StrDeleteVisitor varchar(5000)
		        set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListVisitor + ''
					execute(@StrDeleteVisitor)
		      end

	 if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end

	--insert into #tempFactor
	--	(fldShomareFactorForoosh)
	--Select  fldShomareFactorForoosh from tblForoosh Where (isnumeric(fldShomareFactor) = 1) and fldShomareFactor<>0


	--update #TempShow set fldShomareFactorForoosh=#tempPishFactor.fldShomareFactorForoosh from #tempPishFactor Where #TempShow.fldShomareFactor=#tempPishFactor.fldShomarePishFactor
	
	--update #TempShow set fldShomarePishfactor =tblForoosh.fldShomarePishFactor from tblForoosh Where 
SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldNameKarbar,fldShomareTell  
,fldLock FROM  #TempShow where 
fldMablagh between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

END
GO

-- ===============================================
-- SP: [dbo].[z170ShowList_ReportfactorBargashtAzForoosh_WithUserCode]
-- ===============================================
IF OBJECT_ID(N'dbo.z170ShowList_ReportfactorBargashtAzForoosh_WithUserCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z170ShowList_ReportfactorBargashtAzForoosh_WithUserCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z170ShowList_ReportfactorBargashtAzForoosh_WithUserCode]
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListKarbaran varchar(5000)=null,
	@ListAnbar varchar(5000)=null,
	@ListVisitor varchar(5000)=null,
	@MablaghAz decimal, 
	@MablaghTa decimal,
	@userCode bigint
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 
 create table #TempSumForoosh(
fldShomareFactor bigint,
fldMablaghForoosh decimal,
fldCodeAnbar bigint

)
 create table #TempListCodeAnbar(
fldShomareFactor bigint,
fldCodeAnbar bigint

)
 create table #TempListDateTimeSabtFactor(
fldShomareFactor bigint,
fldTimeSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(20) collate Persian_100_CI_AS,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS
)

 create table #TempListDateFactor(
fldShomareFactor bigint,
fldDateFactor  Nvarchar(20) collate Persian_100_CI_AS
)


create table #TempShow(

fldShomareFactor bigint,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(200) COLLATE Persian_100_CI_AS,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(200) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDateFactor  Nvarchar(200) collate Persian_100_CI_AS,
fldTimeSabtFactor  Nvarchar(200) collate Persian_100_CI_AS,
fldDateSabtFactor  Nvarchar(200) collate Persian_100_CI_AS,
fldCodeVisitor bigint,
fldNameVisitor NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeAnbar bigint,
fldNameAnbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldShomareTell nvarchar(20) COLLATE Persian_100_CI_AS,
fldShomareFactorForoosh bigint,
fldLock nvarchar(10)
)



	delete from #TempListDateTimeSabtFactor
	delete from #TempShow
	delete from #TempListCodeAnbar
	delete from #TempSumForoosh

update tblAmalkardekarbar set  fldNAMEForm =Replace(fldNAMEForm,'ي','ی')
update tblAmalkardekarbar set  NoeAmaliat =Replace(NoeAmaliat,'ي','ی')
insert into #TempListCodeAnbar(fldShomareFactor,fldCodeAnbar)
			(select fldShomareFactor,fldCodeAnbar from tblRizeBargashtAzForoosh where fldRadif=1)

insert into #TempSumForoosh(fldShomareFactor,fldMablaghForoosh,fldCodeAnbar)
			(select tblRizeBargashtAzForoosh.fldShomareFactor,Sum(fldMablaghKhales),0 as fldCodeAnbar from tblRizeBargashtAzForoosh  group by fldShomareFactor )


insert into #TempListDateTimeSabtFactor(fldShomareFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeKarbar,fldNameKarbar)
			(select fldShomare,fldTime,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldCodeKarbar,fldNameKarbar from tblAmalkardekarbar 									 
							 where fldNameForm='برگشت از فروش' and NoeAmaliat=N'جدید' )
			
			--select * from #TempListCodeAnbar
			--select * from #TempSumForoosh
			--select * from #TempListDateTimeSabtFactor
			--select * from #TempListDateFactor

insert into #TempListDateFactor(fldShomareFactor,fldDateFactor)
			(select fldShomareFactor,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							 SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate from tblRizeBargashtAzForoosh)
			--select * from tblRizeBargashtAzForoosh

update R Set R.fldCodeAnbar=(#TempListCodeAnbar.fldCodeAnbar)
								from #TempSumForoosh as R 
								inner join #TempListCodeAnbar on R.fldShomareFactor=#TempListCodeAnbar.fldShomareFactor


insert into #TempShow(fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldCodeKarbar,fldNameKarbar,fldLock)
 select DISTINCT  tblRizeBargashtAzForoosh.fldShomareFactor,fldCodeTafsili
				,tblTafzili.fldSharheTafzili,dbo.tblGroupAshkhas.fldGroupId
 ,dbo.tblGroupAshkhas.fldGroupName,0 as fldMablagh,'' as fldDateFactor,
						'' as fldTimeFacttor,'' as fldDateFacttor,
					tblRizeBargashtAzForoosh.fldCodeVasete ,''as fldNameVisitor,#TempSumForoosh.fldCodeAnbar,'' as fldNameAnbar,0 as fldCodeKarbar,'' as fldNameKarbar,tblBargashtAzForoosh.fldLock
							  
 from tblRizeBargashtAzForoosh 
 inner join tblTafzili on tblTafzili.fldCodeTafzili=tblRizeBargashtAzForoosh.fldCodeTafsili
 inner join tblGroupAshkhas on tblGroupAshkhas.fldGroupId=tblTafzili.fldCodeGroup
 inner join #TempSumForoosh on #TempSumForoosh.fldShomareFactor=tblRizeBargashtAzForoosh.fldShomareFactor
 inner join tblBargashtAzForoosh on tblRizeBargashtAzForoosh.fldShomareFactor=tblBargashtAzForoosh.fldShomareFactorForoosh



							--SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' + 
							-- SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDateShow

	update R Set R.fldMablagh=(#TempSumForoosh.fldMablaghForoosh)
								from #TempShow as R 
								inner join #TempSumForoosh on R.fldShomareFactor=#TempSumForoosh.fldShomareFactor						
	update R Set R.fldNameVisitor=(viewLoadVizitor.fldSharheTafzili)
								from #TempShow as R 
								inner join viewLoadVizitor on R.fldCodeVisitor=viewLoadVizitor.fldCodeTafzili						

	update R Set R.fldNameAnbar=(viewGetAnbarForComboBox.fldNameAnbar)
								from #TempShow as R 
								inner join viewGetAnbarForComboBox on R.fldCodeAnbar=viewGetAnbarForComboBox.fldCode
									
	update R Set R.fldTimeSabtFactor=(#TempListDateTimeSabtFactor.fldTimeSabtFactor),R.fldDateSabtFactor=(#TempListDateTimeSabtFactor.fldDateSabtFactor)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor
	

	update R Set R.fldNameKarbar=(#TempListDateTimeSabtFactor.fldNameKarbar),R.fldCodeKarbar=(#TempListDateTimeSabtFactor.fldCodeKarbar)
								from #TempShow as R 
								inner join #TempListDateTimeSabtFactor on R.fldShomareFactor=#TempListDateTimeSabtFactor.fldShomareFactor

	update R Set R.fldDateFactor=(#TempListDateFactor.fldDateFactor)
								from #TempShow as R 
								inner join #TempListDateFactor on R.fldShomareFactor=#TempListDateFactor.fldShomareFactor

	update #TempShow set fldShomareTell=tbl5.fldShomare from
		(select fldShomare,fldcodetafzili from
			(SELECT         fldcodetafzili,row_number() over (partition by fldcodetafzili order by fldcodetafzili) RowNo,fldShomare
			FROM            [tblDaftarcheTell]) DB_Address
			where RowNo=1) as tbl5 
			where #TempShow.fldCodetafzili=tbl5.fldCodeTafzili

	
	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

	if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
	if @ListAnbar <>''
   begin
		 declare @StrDeleteAnbar varchar(5000)
	     set  @StrDeleteAnbar='delete from #TempShow 
		 where '+ @ListAnbar + ''
		execute(@StrDeleteAnbar)
	end

	if @ListVisitor <>''
		      begin
		       declare @StrDeleteVisitor varchar(5000)
		        set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListVisitor + ''
					execute(@StrDeleteVisitor)
		      end

	 if @ListKarbaran<>''
		      begin
		       declare @StrDeleteKarbar varchar(5000)
		        set  @StrDeleteKarbar='delete from #TempShow 
		            where '+ @ListKarbaran + ''
					execute(@StrDeleteKarbar)
		      end

	--insert into #tempFactor
	--	(fldShomareFactorForoosh)
	--Select  fldShomareFactorForoosh from tblForoosh Where (isnumeric(fldShomareFactor) = 1) and fldShomareFactor<>0


	--update #TempShow set fldShomareFactorForoosh=#tempPishFactor.fldShomareFactorForoosh from #tempPishFactor Where #TempShow.fldShomareFactor=#tempPishFactor.fldShomarePishFactor
	
	--update #TempShow set fldShomarePishfactor =tblForoosh.fldShomarePishFactor from tblForoosh Where 

-- ##########################################################
-- #######Group Ashkhas Limitation###########################
-- ##########################################################
declare @accessCodes table(code bigint)
insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
-- ##########################################################

SELECT  ROW_NUMBER() OVER(ORDER BY fldShomareFactor) as fldRadif, fldShomareFactor ,fldCodeTafzili,fldSharhTafzili,fldCodeGroupAshkhas
,fldNameGroupAshkhas,fldMablagh,fldDateFactor,fldTimeSabtFactor,fldDateSabtFactor,fldCodeVisitor,fldNameVisitor,fldCodeAnbar,fldNameAnbar,fldCodeKarbar,fldNameKarbar,fldShomareTell  
,fldLock FROM  #TempShow where 
fldCodeTafzili in (select code from @accessCodes) and
fldMablagh between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

END
GO

-- ===============================================
-- SP: [dbo].[z171ShowList_ReportHazine]
-- ===============================================
IF OBJECT_ID(N'dbo.z171ShowList_ReportHazine', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z171ShowList_ReportHazine] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z171ShowList_ReportHazine]
	@ListHazine varchar(5000)=null,
	@MablaghAz decimal, 
	@MablaghTa decimal
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 
create table #TempShowHazine(
id bigint,
fldCodeHazune bigint,
fldNameHazine NVarchar(100) COLLATE Persian_100_CI_AS

)

create table #TempShow(
fldShomareHazine bigint,
fldShomareSanad bigint,
fldCodeHazune bigint,
fldNameHazine NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDate NVarchar(100) COLLATE Persian_100_CI_AS,
fldSharh NVarchar(200) COLLATE Persian_100_CI_AS
)


		declare @strCodeKol nvarchar(100)
	execute CodeKolHesab 'hazine', @strCodeKol output
	--execute ShowHesabKolMoin @strCodeKol
	--insert into #TempShowHazine(fldCodeHazune,fldNameHazine,id)
	--select [fldCodeHesab],[fldSharheHesab],[ID] from tblKolMoin
	--	Where fldCodeHesab<>@strCodeKol and left(fldCodeHesab,len(@strCodeKol))=@strCodeKol
	--	order by fldCodeHesab

	declare @lngTooleMoin bigint
	set @lngTooleMoin=(Select top(1) Convert(dec,fldKol)+ Convert(dec,fldMoin) from tblPaye)

	insert into #TempShowHazine(fldCodeHazune,fldNameHazine,id)
	select [fldCodeHesab],[fldSharheHesab],[ID] from tblKolMoin
		Where  SUBSTRING(fldCodeHesab,1,1)=SUBSTRING (@strCodeKol,1,1) AND len(fldCodeHesab)=@lngTooleMoin
		order by fldCodeHesab

insert into #TempShow(fldShomareHazine,fldShomareSanad,fldCodeHazune,fldNameHazine,fldMablagh,fldDate,fldSharh)
 select tblPardakht.fldShomarePardakht as fldShomareHazine,fldSanad,#TempShowHazine.fldCodeHazune,#TempShowHazine.fldNameHazine,fldBedehkar,fldDate,fldSharh
  from tblSodooreSanad inner join
  #TempShowHazine on #TempShowHazine.fldCodeHazune=tblSodooreSanad.fldMoinKamel  inner join
  tblPardakht on tblPardakht.fldShomareSanad=tblSodooreSanad.fldSanad
  where tblSodooreSanad.fldType='hazine' and fldBedehkar>0 
  and fldBedehkar between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

  	if @ListHazine <>''
   begin
		 declare @StrDeleteHazine varchar(5000)
	     set  @StrDeleteHazine='delete from #TempShow 
		 where '+ @ListHazine + ''
		execute(@StrDeleteHazine)
	end

select ROW_NUMBER() OVER(ORDER BY fldShomareHazine) as fldRadif, fldShomareHazine,fldShomareSanad,fldCodeHazune,fldNameHazine,fldMablagh
,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' +
SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldSharh from #TempShow

END
GO

-- ===============================================
-- SP: [dbo].[z172ShowList_ReportDaramad]
-- ===============================================
IF OBJECT_ID(N'dbo.z172ShowList_ReportDaramad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z172ShowList_ReportDaramad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z172ShowList_ReportDaramad]
	@ListDaramad varchar(5000)=null,
	@ListAshkhas varchar(5000)=null,
	@MablaghAz decimal, 
	@MablaghTa decimal
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 
create table #TempShowDaramad(
id bigint,
fldCodeDaramad bigint,
fldNameDaramad NVarchar(100) COLLATE Persian_100_CI_AS

)

create table #TempShow(
fldShomareDaramad bigint,
fldShomareSanad bigint,
fldCodeDaramad bigint,
fldNameDaramad NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldDate NVarchar(100) COLLATE Persian_100_CI_AS,
fldSharh NVarchar(200) COLLATE Persian_100_CI_AS
)


		declare @strCodeKol nvarchar(100)
	execute CodeKolHesab 'daramad', @strCodeKol output
--	execute ShowHesabKolMoin @strCodeKol
	insert into #TempShowDaramad(fldCodeDaramad,fldNameDaramad,id)
	select [fldCodeHesab],[fldSharheHesab],[ID] from tblKolMoin
		Where fldCodeHesab<>@strCodeKol and left(fldCodeHesab,len(@strCodeKol))=@strCodeKol
		order by fldCodeHesab

insert into #TempShow(fldShomareDaramad,fldShomareSanad,fldCodeDaramad,fldNameDaramad,fldMablagh,fldCodeTafzili,fldSharhTafzili,fldDate,fldSharh)
 select tblDaryaft.fldShomareDaryaft as fldShomareDaramad,fldSanad,#TempShowDaramad.fldCodeDaramad
 ,#TempShowDaramad.fldNameDaramad,fldBestankar,tblSodooreSanad.fldCodeTafzili,'' as fldSharhTafzili,fldDate,fldSharh
  from tblSodooreSanad inner join
  #TempShowDaramad on #TempShowDaramad.fldCodeDaramad=tblSodooreSanad.fldMoinKamel  inner join
  tblDaryaft on tblDaryaft.fldShomareSanad=tblSodooreSanad.fldSanad
  where tblSodooreSanad.fldType='daramad' and fldBestankar>0 
  and fldBestankar between CONVERT(nvarchar(50),@MablaghAz) and CONVERT(nvarchar(50),@MablaghTa)

  	update R Set R.fldSharhTafzili=(tblTafzili.fldSharheTafzili)
								from #TempShow as R 
								inner join tblTafzili on R.fldCodeTafzili=tblTafzili.fldCodeTafzili	

  	if @ListDaramad <>''
   begin
		 declare @StrDeleteDaramad varchar(5000)
	     set  @StrDeleteDaramad='delete from #TempShow 
		 where '+ @ListDaramad + ''
		execute(@StrDeleteDaramad)
	end				

  	if @ListAshkhas <>''
   begin
		 declare @StrDeleteAshkhas varchar(5000)
	     set  @StrDeleteAshkhas='delete from #TempShow 
		 where '+ @ListAshkhas + ''
		execute(@StrDeleteAshkhas)
	end

select ROW_NUMBER() OVER(ORDER BY fldShomareDaramad) as fldRadif, fldShomareDaramad,fldShomareSanad,fldCodeDaramad,fldNameDaramad,fldMablagh
,fldCodeTafzili,fldSharhTafzili,
SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' +
SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldSharh from #TempShow

END
GO

-- ===============================================
-- SP: [dbo].[z174ShowList_ReportEnteghalBainAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.z174ShowList_ReportEnteghalBainAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z174ShowList_ReportEnteghalBainAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z174ShowList_ReportEnteghalBainAnbar]
	--@ListRanande varchar(5000)=null,
	@ListCodeShakhsTahvilDahande varchar(5000)=null,
	@ListCodeShakhsTahvilGirande varchar(5000)=null,
    @ListCodeAnbarTahvilDahande varchar(5000)=null,
	@ListCodeAnbarTahvilGirande varchar(5000)=null,
	@ListKarbaran varchar(5000)=null
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 



create table #TempShow(
fldShomareEnteghal bigint,

fldCodeShakhsTahvilDahande bigint,
fldNameShakhsTahvilDahande NVarchar(100) COLLATE Persian_100_CI_AS,

fldCodeShakhsTahvilGirande bigint,
fldNameShakhsTahvilGirande NVarchar(100) COLLATE Persian_100_CI_AS,

fldCodeAnbarTahvilDahande bigint,
fldNameAnbarTahvilDahande NVarchar(100) COLLATE Persian_100_CI_AS,

fldCodeAnbarTahvilGirande bigint,
fldNameAnbarTahvilGirande NVarchar(100) COLLATE Persian_100_CI_AS,

fldDate NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldSharh NVarchar(100) COLLATE Persian_100_CI_AS
)

delete #TempShow



insert into #TempShow(fldShomareEnteghal
					  ,fldCodeShakhsTahvilDahande,fldNameShakhsTahvilDahande
					  ,fldCodeShakhsTahvilGirande,fldNameShakhsTahvilGirande
					  ,fldCodeAnbarTahvilDahande,fldNameAnbarTahvilDahande
					  ,fldCodeAnbarTahvilGirande,fldNameAnbarTahvilGirande
					  ,fldDate
					  ,fldCodeKarbar
					  ,fldNameKarbar
					  ,fldSharh)
select distinct tblRizeForoosh.fldShomareEnteghal
			,tblRizeForoosh.fldCodeTafsili as fldCodeShakhsTahvilDahande
			,'' as fldNameShakhsTahvilDahande
			,tblRizeKharid.fldCodeTafsili as fldCodeShakhsTahvilGirande
			,'' as fldNameShakhsTahvilGirande
			,tblRizeForoosh.fldCodeAnbar as fldCodeAnbarTahvilDahande
			,'' as fldNameAnbarTahvilDahande
			,tblRizeKharid.fldCodeAnbar as fldCodeAnbarTahvilGirande
			,'' as fldNameAnbarTahvilGirande
			,tblRizeForoosh.fldDate
			,tblRizeForoosh.fldCodeUser,'' as fldNameKarbar
			,tblRizeForoosh.fldSharhKala  from tblRizeForoosh inner join
			tblRizeKharid on tblRizeForoosh.fldShomareEnteghal=tblRizeKharid.fldShomareEnteghal
where tblRizeForoosh.fldType='enteghal'

--select fldShomareEnteghal,fldCodeTafsili,fldDate from tblRizeKharid where fldType='enteghal'

--select * from #TempShow

	update R Set R.fldNameShakhsTahvilDahande=(tblTafzili.fldSharheTafzili)
								from #TempShow as R 
								inner join tblTafzili on R.fldCodeShakhsTahvilDahande=tblTafzili.fldCodeTafzili

	update R Set R.fldNameShakhsTahvilGirande=(tblTafzili.fldSharheTafzili)
								from #TempShow as R 
								inner join tblTafzili on R.fldCodeShakhsTahvilGirande=tblTafzili.fldCodeTafzili
								
	update R Set R.fldNameAnbarTahvilDahande=(tblAnbar.fldNameAnbar)
								from #TempShow as R 
								inner join tblAnbar on R.fldCodeAnbarTahvilDahande=tblAnbar.fldCode

	update R Set R.fldNameAnbarTahvilGirande=(tblAnbar.fldNameAnbar)
								from #TempShow as R 
								inner join tblAnbar on R.fldCodeAnbarTahvilGirande=tblAnbar.fldCode
		
		if @ListKarbaran <>''
   begin
		 declare @StrDeleteKarbaran varchar(5000)
	     set  @StrDeleteKarbaran='delete from #TempShow 
		 where '+ @ListKarbaran + ''
		execute(@StrDeleteKarbaran)
	end

	if @ListCodeAnbarTahvilDahande <>''
   begin
		 declare @StrDeleteAnbarTahvilDahande varchar(5000)
	     set  @StrDeleteAnbarTahvilDahande='delete from #TempShow 
		 where '+ @ListCodeAnbarTahvilDahande + ''
		execute(@StrDeleteAnbarTahvilDahande)
	end
	if @ListCodeAnbarTahvilGirande <>''
   begin
		 declare @StrDeleteAnbarTahvilGirande varchar(5000)
	     set  @StrDeleteAnbarTahvilGirande='delete from #TempShow 
		 where '+ @ListCodeAnbarTahvilGirande + ''
		execute(@StrDeleteAnbarTahvilGirande)
	end
	if @ListCodeShakhsTahvilDahande <>''
   begin
		 declare @StrDeleteShakhsTahvilDahande varchar(5000)
	     set  @StrDeleteShakhsTahvilDahande='delete from #TempShow 
		 where '+ @ListCodeShakhsTahvilDahande + ''
		execute(@StrDeleteShakhsTahvilDahande)
	end													

	 	if @ListCodeShakhsTahvilGirande <>''
   begin
		 declare @StrDeleteShakhsTahvilGirande varchar(5000)
	     set  @StrDeleteShakhsTahvilGirande='delete from #TempShow 
		 where '+ @ListCodeShakhsTahvilGirande + ''
		execute(@StrDeleteShakhsTahvilGirande)
	end



select ROW_NUMBER() OVER(ORDER BY fldShomareEnteghal) as fldRadif,
fldShomareEnteghal
,fldNameAnbarTahvilDahande
,fldNameShakhsTahvilDahande
,fldNameAnbarTahvilGirande
,fldNameShakhsTahvilGirande,
SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' +
SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldNameKarbar,fldSharh
,fldCodeShakhsTahvilDahande
,fldCodeKarbar
,fldCodeShakhsTahvilGirande
,fldCodeAnbarTahvilDahande
,fldCodeAnbarTahvilGirande from #TempShow


END
GO

-- ===============================================
-- SP: [dbo].[z175ShowList_ReportAsnad]
-- ===============================================
IF OBJECT_ID(N'dbo.z175ShowList_ReportAsnad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z175ShowList_ReportAsnad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z175ShowList_ReportAsnad]
	@AzSanad bigint,
	@TaSanad bigint,
	@AzDate bigint,
	@TaDate bigint,
	@ListKarbaran varchar(5000)=null,
	@ListKarbaranUpdate varchar(5000)=null
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 
	--declare @AzSanad bigint = 1
	--declare @TaSanad bigint = 90000
	--declare @AzDate bigint = 13980101
	--declare @TaDate bigint = 13981231
	--declare @ListKarbaran varchar(5000)= '1006'
	--declare @ListKarbaranUpdate varchar(5000)=null

create table #TempShow(
fldShomareSanad bigint,
fldShomare bigint,
fldDate NVarchar(100) COLLATE Persian_100_CI_AS,
fldType NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeKarbarUpdate bigint,
fldNameKarbarUpdate NVarchar(100) COLLATE Persian_100_CI_AS,
fldSharh NVarchar(max) COLLATE Persian_100_CI_AS
)

create table #Temp(
fldShomare bigint,
fldShomareSanad bigint,
fldCodeKarbar bigint,
fldType NVarchar(100) COLLATE Persian_100_CI_AS

)
create table #TempKarbarUpdate(
id bigint,
fldShomareSanad bigint,
fldCodeKarbarUpdate bigint,
fldNameKarbarUpdate NVarchar(100) COLLATE Persian_100_CI_AS,
fldType NVarchar(100) COLLATE Persian_100_CI_AS

)


delete #TempShow
delete #TempKarbarUpdate
delete #Temp


----------------------------آخرین تغییرکننده هزینه ، درآمد --------------------------
insert #TempKarbarUpdate(id,fldShomareSanad,fldCodeKarbarUpdate,fldNameKarbarUpdate,fldType)
select distinct id,fldSanad,fldCodeKarbar,fldNameKarbar,fldNameForm from tblAmalkardekarbar 
where NoeAmaliat='ویرایش' and fldSanad<>0 and id in (select max(id) from tblAmalkardekarbar group by fldSanad) order by id desc
----------------------------آخرین تغییرکننده سند-------------------------------
insert #TempKarbarUpdate(id,fldShomareSanad,fldCodeKarbarUpdate,fldNameKarbarUpdate,fldType)
select distinct id,fldShomare,fldCodeKarbar,fldNameKarbar,fldNameForm from tblAmalkardekarbar 
where fldNameForm='سند' and NoeAmaliat=N'ویرایش' and tblAmalkardekarbar.id in (select max(tblAmalkardekarbar.id) from tblAmalkardekarbar inner join
tblSodooreSanad on tblSodooreSanad.fldSanad=tblAmalkardekarbar.fldShomare where fldNameForm='سند' and NoeAmaliat=N'ویرایش' group by fldShomare) order by id desc
----------------------------آخرین تغییرکننده فروش-------------------------------
insert #TempKarbarUpdate(id,fldShomareSanad,fldCodeKarbarUpdate,fldNameKarbarUpdate,fldType)
select  tblAmalkardekarbar.id,tblForoosh.fldShomareSanad,fldCodeKarbar,fldNameKarbar,fldNameForm from tblAmalkardekarbar 
inner join tblForoosh on tblForoosh.fldShomareFactorForoosh=tblAmalkardekarbar.fldShomare
where fldNameForm='فروش' and NoeAmaliat=N'ویرایش' and tblAmalkardekarbar.id in (select max(tblAmalkardekarbar.id) from tblAmalkardekarbar inner join
tblSodooreSanad on tblSodooreSanad.fldSanad=tblAmalkardekarbar.fldShomare where fldNameForm='فروش' and NoeAmaliat=N'ویرایش' group by fldShomare) order by id desc
----------------------------آخرین تغییرکننده برگشت از فروش-------------------------------
insert #TempKarbarUpdate(id,fldShomareSanad,fldCodeKarbarUpdate,fldNameKarbarUpdate,fldType)
select distinct tblAmalkardekarbar.id,tblBargashtAzForoosh.fldShomareSanad,fldCodeKarbar,fldNameKarbar,fldNameForm from tblAmalkardekarbar 
inner join tblBargashtAzForoosh on tblBargashtAzForoosh.fldShomareFactorForoosh=tblAmalkardekarbar.fldShomare
where fldNameForm='برگشت از فروش' and NoeAmaliat=N'ویرایش' and tblAmalkardekarbar.id in (select max(tblAmalkardekarbar.id) from tblAmalkardekarbar inner join
tblSodooreSanad on tblSodooreSanad.fldSanad=tblAmalkardekarbar.fldShomare where fldNameForm='برگشت از فروش' and NoeAmaliat=N'ویرایش' group by fldShomare) order by id desc
----------------------------آخرین تغییرکننده خرید-------------------------------
insert #TempKarbarUpdate(id,fldShomareSanad,fldCodeKarbarUpdate,fldNameKarbarUpdate,fldType)
select distinct tblAmalkardekarbar.id,tblKharid.fldShomareSanad,fldCodeKarbar,fldNameKarbar,fldNameForm from tblAmalkardekarbar 
inner join tblKharid on tblKharid.fldShomareFactorKharid=tblAmalkardekarbar.fldShomare
where fldNameForm=N'خرید' and NoeAmaliat=N'ویرایش' and tblAmalkardekarbar.id in (select max(tblAmalkardekarbar.id) from tblAmalkardekarbar inner join
tblSodooreSanad on tblSodooreSanad.fldSanad=tblAmalkardekarbar.fldShomare where fldNameForm=N'خرید' and NoeAmaliat=N'ویرایش' group by fldShomare) order by id desc
----------------------------آخرین تغییرکننده برگشت از خرید-------------------------------
insert #TempKarbarUpdate(id,fldShomareSanad,fldCodeKarbarUpdate,fldNameKarbarUpdate,fldType)
select distinct tblAmalkardekarbar.id,tblBargashtAzKharid.fldShomareSanad,fldCodeKarbar,fldNameKarbar,fldNameForm from tblAmalkardekarbar 
inner join tblBargashtAzKharid on tblBargashtAzKharid.fldShomareFactorKharid=tblAmalkardekarbar.fldShomare
where fldNameForm=N'برگشت از خرید' and NoeAmaliat=N'ویرایش' and tblAmalkardekarbar.id in (select max(tblAmalkardekarbar.id) from tblAmalkardekarbar inner join
tblSodooreSanad on tblSodooreSanad.fldSanad=tblAmalkardekarbar.fldShomare where fldNameForm=N'برگشت از خرید' and NoeAmaliat=N'ویرایش' group by fldShomare) order by id desc

---------------daryaft----------------------
insert into #Temp(fldShomareSanad,fldShomare,fldCodeKarbar,fldType)
 select distinct fldShomareSanad,fldShomareDaryaft,tblAmalkardekarbar.fldCodeKarbar,'دریافت'as fldType from tblDaryaft
 inner join tblAmalkardekarbar on tblAmalkardekarbar.fldShomare=fldShomareDaryaft
 where fldNameForm='دریافت' and NoeAmaliat='جدید'   

---------------pardakht----------------------
insert into #Temp(fldShomareSanad,fldShomare,fldCodeKarbar,fldType)
select fldShomareSanad,fldShomarePardakht,tblAmalkardekarbar.fldCodeKarbar,'پرداخت'as fldType from tblPardakht
 inner join tblAmalkardekarbar on tblAmalkardekarbar.fldShomare=fldShomarePardakht
 where fldNameForm='پرداخت' and NoeAmaliat='جدید'   

  ---------------enteghalevajh----------------------
insert into #Temp(fldShomareSanad,fldShomare,fldCodeKarbar,fldType)
select fldShomareSanad,fldShomarePardakht,tblAmalkardekarbar.fldCodeKarbar,'پرداخت'as fldType from tblPardakht
 inner join tblAmalkardekarbar on tblAmalkardekarbar.fldShomare=fldShomarePardakht
 where fldNameForm='انتقال وجه' and NoeAmaliat='جدید'   

----------------foroosh----------------------
insert into #Temp(fldShomareSanad,fldShomare,fldCodeKarbar,fldType)
	select fldShomareSanad,fldShomareFactorForoosh,tblAmalkardekarbar.fldCodeKarbar,'فروش' as fldType from tblForoosh inner join
  tblAmalkardekarbar on tblAmalkardekarbar.fldShomare=tblForoosh.fldShomareFactorForoosh 
  where tblAmalkardekarbar.fldNameForm='فروش' and NoeAmaliat=N'جدید'   


----------------barghashtAzforoosh----------------------

insert into #Temp(fldShomareSanad,fldShomare,fldCodeKarbar,fldType)
	select fldShomareSanad,fldShomareFactorForoosh,tblAmalkardekarbar.fldCodeKarbar,'برگشت از فروش' as fldType from tblBargashtAzForoosh inner join
  tblAmalkardekarbar on tblAmalkardekarbar.fldShomare=tblBargashtAzForoosh.fldShomareFactorForoosh 
  where tblAmalkardekarbar.fldNameForm='برگشت از فروش' and NoeAmaliat=N'جدید'   
	
----------------kharid----------------------
insert into #Temp(fldShomareSanad,fldShomare,fldCodeKarbar,fldType)
	select fldShomareSanad,fldShomareFactorKharid,tblAmalkardekarbar.fldCodeKarbar,'خرید' as fldType from tblKharid inner join
  tblAmalkardekarbar on tblAmalkardekarbar.fldShomare=tblKharid.fldShomareFactorKharid 
  where tblAmalkardekarbar.fldNameForm=N'خرید' and NoeAmaliat=N'جدید'   
 ----------------bargashtazkharid----------------------
insert into #Temp(fldShomareSanad,fldShomare,fldCodeKarbar,fldType)
	select fldShomareSanad,fldShomareFactorKharid,tblAmalkardekarbar.fldCodeKarbar,'برگشت از خرید' as fldType from tblBargashtAzKharid inner join
  tblAmalkardekarbar on tblAmalkardekarbar.fldShomare=tblBargashtAzKharid.fldShomareFactorKharid 
  where tblAmalkardekarbar.fldNameForm=N'برگشت از خرید' and NoeAmaliat=N'جدید'   
  ----------------hazine----------------------
insert into #Temp(fldShomareSanad,fldShomare,fldCodeKarbar,fldType)
	select distinct tblSodooreSanad.fldSanad,tblAmalkardekarbar.fldShomare,tblAmalkardekarbar.fldCodeKarbar,'هزینه'as fldType from tblSodooreSanad 
	inner join tblAmalkardekarbar on tblAmalkardekarbar.fldSanad=tblSodooreSanad.fldSanad
	where fldType='hazine' and NoeAmaliat='جدید'   
  ----------------daramad----------------------
insert into #Temp(fldShomareSanad,fldShomare,fldCodeKarbar,fldType)
	select distinct tblSodooreSanad.fldSanad,tblAmalkardekarbar.fldShomare,tblAmalkardekarbar.fldCodeKarbar,'درآمد'as fldType from tblSodooreSanad 
	inner join tblAmalkardekarbar on tblAmalkardekarbar.fldSanad=tblSodooreSanad.fldSanad
	where fldType='daramad' and NoeAmaliat='جدید'   

  ----------------sanad----------------------
insert into #Temp(fldShomareSanad,fldShomare,fldCodeKarbar,fldType)
				select distinct fldShomare,fldShomare,fldCodeKarbar,fldNameForm from tblAmalkardekarbar 
				where fldNameForm='سند'   

insert into #Temp(fldShomareSanad,fldShomare,fldCodeKarbar,fldType)
	select distinct fldSanad,0,-1,'سایر' from tblSodooreSanad where fldSanad not in (select fldShomareSanad from #Temp)
---------------------------------------------------
 insert into #TempShow(fldShomareSanad,fldShomare,fldDate,fldCodeKarbar,fldNameKarbar,fldType) 

 select fldShomareSanad,fldShomare,0 as fldDate,fldCodeKarbar,'' as fldNameKarbar,fldType  from #Temp
	where fldShomareSanad between @AzSanad and @TaSanad

-----------------------------------------------------
	update R Set R.fldSharh=(tblSodooreSanad.fldSharh)
								from #TempShow as R 
								inner join tblSodooreSanad on R.fldShomareSanad=tblSodooreSanad.fldSanad	
								where tblSodooreSanad.fldSharh<>''					
	
		update R Set R.fldDate=(tblSodooreSanad.fldDate)
								from #TempShow as R 
								inner join tblSodooreSanad on R.fldShomareSanad=tblSodooreSanad.fldSanad
									
		update R Set R.fldNameKarbar=(tblSecurity.fldUser)
								from #TempShow as R 
								inner join tblSecurity on R.fldCodeKarbar=tblSecurity.fldCode	
										


	update R Set R.fldCodeKarbarUpdate=(#TempKarbarUpdate.fldCodeKarbarUpdate),R.fldNameKarbarUpdate=(#TempKarbarUpdate.fldNameKarbarUpdate)
								from #TempShow as R 
								inner join #TempKarbarUpdate on R.fldShomareSanad=#TempKarbarUpdate.fldShomareSanad	
------------------------------------------------------------								
		if @ListKarbaran <>''
   begin
		 declare @StrDeleteKarbaran varchar(5000)
	     set  @StrDeleteKarbaran='delete from #TempShow 
		 where fldCodeKarbar not in ('+ @ListKarbaran + ')'
		execute(@StrDeleteKarbaran)
	end
				if @ListKarbaranUpdate <>''
   begin
		 declare @StrDeleteKarbaranUpdate varchar(5000)
	     set  @StrDeleteKarbaranUpdate='delete from #TempShow 
		 where fldCodeKarbarUpdate not in ('+ @ListKarbaranUpdate + ') or fldNameKarbarUpdate is null '
		execute(@StrDeleteKarbaranUpdate)
	end	
	--delete from #TempShow where fldNameKarbarUpdate <> N'تبلت' or fldNameKarbarUpdate is null
--------------------------------------------------------------
select  ROW_NUMBER() OVER(ORDER BY fldShomareSanad) as fldRadif,
fldShomareSanad
,fldShomare
,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' +
SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate
,fldNameKarbar
,fldType
,fldSharh
,fldNameKarbarUpdate
 from #TempShow


END
GO

-- ===============================================
-- SP: [dbo].[z176ShowList_ReportEnteghalVajh]
-- ===============================================
IF OBJECT_ID(N'dbo.z176ShowList_ReportEnteghalVajh', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z176ShowList_ReportEnteghalVajh] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z176ShowList_ReportEnteghalVajh]
	@ListKarbaran varchar(5000),
    @ListBankSadere varchar(5000),
	@ListSandooghSadere varchar(5000),
	@ListHesabMaghsad varchar(5000),
	@AzMablagh decimal,
	@TaMablagh decimal,
	@AzDate bigint,
	@TaDate bigint
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 


create table #TempShow(
fldShomareEnteghal bigint,
fldSanad bigint,
fldBankSadere bigint,
fldSandooghSadere bigint,
fldHesabMaghsad bigint,
fldBankSadereShow NVarchar(100) COLLATE Persian_100_CI_AS,
fldSandooghSadereShow NVarchar(100) COLLATE Persian_100_CI_AS,
fldHesabMaghsadShow NVarchar(100) COLLATE Persian_100_CI_AS,
fldDate NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldSharh NVarchar(100) COLLATE Persian_100_CI_AS
)


	
	declare @strCodeKoleHesab nvarchar(50)
	execute CodeKolHesab 'bank',@strcodekolehesab output

	declare @strCodeKoleHesabSandough nvarchar(10)
	execute CodeKolHesab 'sandoogh',@strCodeKoleHesabSandough output

	insert into #TempShow(fldShomareEnteghal,fldSanad,fldBankSadere,fldSandooghSadere,fldHesabMaghsad,fldBankSadereShow,fldSandooghSadereShow,fldHesabMaghsadShow,fldDate,fldMablagh,fldCodeKarbar,fldNameKarbar,fldSharh)
	select distinct tblAmalkardekarbar.fldShomare,tblSodooreSanad.fldSanad, fldBankSadere = Case When fldCodeKol = @strCodeKoleHesab THEN fldMoinKamel Else 0 END ,
	CASE WHEN fldCodeKol=@strCodeKoleHesabSandough THEN fldMoinKamel ELSE 0 END as  fldSandooghSadere,
	0 as fldHesabMaghsad,'' as fldBankSadereShow,'' as fldSandooghSadereShow,'' as fldHesabMaghsadShow,
	tblAmalkardekarbar.fldDate,fldBestankar as fldMablagh,fldCodeKarbar,fldNameKarbar,tblSodooreSanad.fldSharh
	from tblSodooreSanad inner join tblAmalkardekarbar on tblAmalkardekarbar.fldSanad=tblSodooreSanad.fldSanad 
	where tblSodooreSanad.fldType='enteghalevajh' and fldBestankar>0 and tblAmalkardekarbar.fldDate between @AzDate and @TaDate and tblAmalkardekarbar.NoeAmaliat='جدید'



			UPDATE       #TempShow
		SET                fldHesabMaghsad = tblSodooreSanad.fldMoinKamel
																   			
		FROM           tblSodooreSanad    INNER JOIN
								#TempShow  ON tblSodooreSanad.fldSanad=#TempShow.fldSanad  
								where fldType='enteghalevajh' and fldBedehkar>0

		declare @strCodeKolBank nvarchar(10)
	execute CodeKolHesab 'bank',@strCodeKolBank output

				
		UPDATE       #TempShow
		SET                fldBankSadereShow = tblKolMoin.fldSharheHesab
																   			
		FROM           #TempShow    INNER JOIN
								tblKolMoin  ON tblKolMoin.fldCodeHesab=#TempShow.fldBankSadere 
		Where fldCodeHesab<>@strCodeKolBank and left(fldCodeHesab,len(@strCodeKolBank))=@strCodeKolBank
		
		declare @strCodeKolSandoogh nvarchar(10)
	execute CodeKolHesab 'sandoogh',@strCodeKolSandoogh output

				
		UPDATE       #TempShow
		SET                fldSandooghSadereShow = tblKolMoin.fldSharheHesab
																   			
		FROM           #TempShow    INNER JOIN
								tblKolMoin  ON tblKolMoin.fldCodeHesab=#TempShow.fldSandooghSadere 
		Where fldCodeHesab<>@strCodeKolSandoogh and left(fldCodeHesab,len(@strCodeKolSandoogh))=@strCodeKolSandoogh



	declare @strCodeBank nvarchar(10),@strCodeSandoogh nvarchar(10)
    execute  CodeKolHesab 'sandoogh', @strCodeSandoogh output
	execute  CodeKolHesab 'bank', @strCodeBank output

	UPDATE       #TempShow
		SET                fldHesabMaghsadShow = tblKolMoin.fldSharheHesab
																   			
		FROM           #TempShow    INNER JOIN
								tblKolMoin  ON tblKolMoin.fldCodeHesab=#TempShow.fldHesabMaghsad 
		Where fldCodeHesab<>@strCodeSandoogh and fldCodeHesab<>@strCodeBank  and (left(fldCodeHesab,len(@strCodeSandoogh))=@strCodeSandoogh or left(fldCodeHesab,len(@strCodeBank))=@strCodeBank)
	





 
		if @ListKarbaran <>''
   begin
		 declare @StrDeleteKarbaran varchar(5000)
	     set  @StrDeleteKarbaran='delete from #TempShow 
		 where '+ @ListKarbaran + ''
		execute(@StrDeleteKarbaran)
	end
		if @ListBankSadere <>''
   begin
		 declare @StrDeleteBankSadere varchar(5000)
	     set  @StrDeleteBankSadere='delete from #TempShow 
		 where '+ @ListBankSadere + ''
		execute(@StrDeleteBankSadere)
	end	
		if @ListSandooghSadere <>''
   begin
		 declare @StrDeleteSandooghSadere varchar(5000)
	     set  @StrDeleteSandooghSadere='delete from #TempShow 
		 where '+ @ListSandooghSadere + ''
		execute(@StrDeleteSandooghSadere)
	end			
		if @ListHesabMaghsad <>''
   begin
		 declare @StrDeleteHesabMaghsad varchar(5000)
	     set  @StrDeleteHesabMaghsad='delete from #TempShow 
		 where '+ @ListHesabMaghsad + ''
		execute(@StrDeleteHesabMaghsad)
	end		

select ROW_NUMBER() OVER(ORDER BY fldShomareEnteghal) as fldRadif,
fldShomareEnteghal
,fldSanad
,fldBankSadereShow
,fldSandooghSadereShow
,fldHesabMaghsadShow
,SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
SUBSTRING(CONVERT(nvarchar,fldDate), 5, 2) + '/' +
SUBSTRING(CONVERT(nvarchar,fldDate), 7, 2) AS fldDate
,fldMablagh
,fldNameKarbar
,fldSharh
 from #TempShow
 where 
fldMablagh between CONVERT(nvarchar(50),@AzMablagh) and CONVERT(nvarchar(50),@TaMablagh)

END
GO

-- ===============================================
-- SP: [dbo].[z177InsertCheckEbtedaDorehPrdakhti]
-- ===============================================
IF OBJECT_ID(N'dbo.z177InsertCheckEbtedaDorehPrdakhti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z177InsertCheckEbtedaDorehPrdakhti] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z177InsertCheckEbtedaDorehPrdakhti]

@fldCodeSahbeCheck bigint,
@fldShomareCheck bigint,
@fldShomareHesab bigint,
@fldDateSarResid int,
@fldDatePardakht int,
@fldCodeBank int,
@fldShobe nvarchar(50),
@fldMablagh decimal,
@strShomareSanad nvarchar output
as 

begin
	begin transaction AddRecord
		begin try
		
	declare 
		@intShomareSanad int,
		@strResult nvarchar(50),
		@strResult2 nvarchar(50),
		@strVaziat nvarchar(50),
		@strType nvarchar(50),
		@strRadif1 nvarchar(50),
		@strRadif2 nvarchar(50),
		@count int,
		@fldDate int,
	    @day nvarchar(50),
		@month nvarchar(50),
		@year nvarchar(50),
		@kolVaMoin nvarchar(100),
		@kol nvarchar(50),
		@moin nvarchar(50),
		@Toolkol int,
		@Toolmoin int,
		@KolCheck nvarchar(50),
		@jameMablaghKol decimal
		--execute CodeMoinHesab 'check',@kolVaMoin
		set @kolVaMoin=(Select  fldCodeMoinCheckPardakhti from tblTanzimat )
		set @Toolkol=(select fldKol from tblPaye)
		set @Toolmoin=(select fldMoin from tblPaye)
		set @kol=(SUBSTRING(@kolVaMoin,1,@Toolkol))
		set @moin=(SUBSTRING(@kolVaMoin,@Toolkol+1,@Toolmoin))
		
		set @KolCheck=(Select  fldKolSarmaye from tblTanzimat )
		
		set @count= (Select COUNT(fldShomareCheck) from tblCheckePardakhti where fldShomarePardakht=0)
		set @day=(SUBSTRING(CONVERT(nvarchar, @fldDatePardakht), 7, 2))
		set @month=(SUBSTRING(CONVERT(nvarchar, @fldDatePardakht), 5, 2))
		set @year=(SUBSTRING(CONVERT(nvarchar, @fldDatePardakht), 1,4))
		set @fldDate=@fldDatePardakht--(CONVERT(int, @year+@month+@day))
	
	
 if @count>0
begin

 set @strVaziat='Last'
end
 else
begin

	set @strVaziat='First'
end


if @strVaziat='First'
	begin
	


		set @intShomareSanad=(select MAX(CONVERT(dec, fldSanad)+1)as fldSanad from tblSodooreSanad)
		
		execute insertSanadFirst @kol,@moin,@kolVaMoin,@fldCodeSahbeCheck,NULL,0,@fldMablagh,'1',@fldDate,NULL,@day,@month,@year,'checkebtedaPardakhti',0,@intShomareSanad output;
			   
		 execute insertSanadLast @KolCheck,'',@KolCheck,NULL,'1',@fldMablagh,'0',@strRadif1,@fldDate,NULL,@day,@month,@year,'checkebtedaPardakhti',0,@intShomareSanad;
		--execute insertSanadFirst @KolCheck,NULL,@KolCheck,NULL,NULL, @fldMablagh,0,'1',@fldDate,NULL,@day,@month,@year,'ebteda',0,@intShomareSanad;
		
			insert into tblCheckePardakhti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,
									fldDatePardakht,fldCodeSahebeCheck,fldShomarePardakht,fldCodeSahebeHesab,fldVasete,fldSanad,fldRadif)
							 Values(@fldShomareCheck,@fldShomareHesab,@fldDateSarResid,@fldCodeBank,@fldShobe,@fldMablagh,
									@fldDatePardakht,@fldCodeSahbeCheck,0,NULL,'',@intShomareSanad,'1')
	end

if @strVaziat='Last'
	begin
	 	set @intShomareSanad=(select distinct CONVERT(dec, fldSanad) from tblSodooreSanad where fldType='checkebtedaPardakhti')
	    set @strRadif1=(CONVERT(nvarchar, @count+1))
		set @jameMablaghKol=(select sum(fldMablagh)+@fldMablagh from tblCheckePardakhti where fldShomarePardakht=0)
		
		delete from tblSodooreSanad Where fldSanad=@intShomareSanad and fldBedehkar>0
		execute insertSanadLast @kol,@moin,@kolVaMoin,@fldCodeSahbeCheck,'1','0',@fldMablagh,@strRadif1,@fldDate,NULL,@day,@month,@year,'checkebtedaPardakhti',0,@intShomareSanad;
	    set @strRadif2=(CONVERT(nvarchar, @count+2))
		execute insertSanadLast @KolCheck,'',@KolCheck,NULL,'1',@jameMablaghKol,'0',@strRadif2,@fldDate,NULL,@day,@month,@year,'checkebtedaPardakhti',0,@intShomareSanad;
	--execute insertSanadLast '1','1','1',@fldCodeSahbeCheck,'1',@fldMablagh,0,2,971003,NULL,'03','10','97','checkebteda',0,'36';
		
			insert into tblCheckePardakhti (fldShomareCheck,fldShomareHesab,fldDateSarResid,fldCodeBank,fldShobe,fldMablagh,
									fldDatePardakht,fldCodeSahebeCheck,fldShomarePardakht,fldCodeSahebeHesab,fldVasete,fldSanad,fldRadif)
							 Values(@fldShomareCheck,@fldShomareHesab,@fldDateSarResid,@fldCodeBank,@fldShobe,@fldMablagh,
									@fldDatePardakht,@fldCodeSahbeCheck,0,NULL,'',@intShomareSanad,@strRadif1)
	end

		--select * from tblSodooreSanad
	--select * from tblCheckePardakhti
	--delete tblSodooreSanad where fldSanad=83
	update tblSodooreSanad set fldDate= @fldDate,fldDay=@day,fldMonth=@month,fldYear=@year Where fldSanad=@intShomareSanad 	
		
		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

-- ===============================================
-- SP: [dbo].[z178ShowCheakEbtedaDorehPardakhti]
-- ===============================================
IF OBJECT_ID(N'dbo.z178ShowCheakEbtedaDorehPardakhti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z178ShowCheakEbtedaDorehPardakhti] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z178ShowCheakEbtedaDorehPardakhti]

as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
  create table #TempListCodeBank(
fldCodeBank bigint,
fldNameBank nvarchar(50)
)


	
			 	declare @strCodeKoleHesab nvarchar(10)
				execute CodeKolHesab 'bank',@strcodekolehesab output

		insert into #TempListCodeBank(fldNameBank,fldCodeBank)
	select [fldSharheHesab] as fldNameBank,[fldCodeHesab] from tblKolMoin
		where  fldCodeHesab like @strCodeKoleHesab + '%' and len(fldCodeHesab)>len(@strCodeKoleHesab)
		order by fldCodeHesab

	select dbo.tblCheckePardakhti.ID,fldSanad,fldCodeSahebeCheck,dbo.tblTafzili.fldSharheTafzili,fldShomareCheck,dbo.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,
			#TempListCodeBank.fldNameBank,#TempListCodeBank.fldCodeBank,tblCheckePardakhti.fldShobe,fldMablagh
		from dbo.tblCheckePardakhti inner join
		#TempListCodeBank on dbo.tblCheckePardakhti.fldCodeBank=#TempListCodeBank.fldCodeBank inner join
		dbo.tblTafzili on dbo.tblCheckePardakhti.fldCodeSahebeCheck=dbo.tblTafzili.fldCodeTafzili
		where dbo.tblCheckePardakhti.fldShomarePardakht=0
END
GO

-- ===============================================
-- SP: [dbo].[z179UpdateCheakEbtedaDorehPardakhti]
-- ===============================================
IF OBJECT_ID(N'dbo.z179UpdateCheakEbtedaDorehPardakhti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z179UpdateCheakEbtedaDorehPardakhti] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[z179UpdateCheakEbtedaDorehPardakhti]
@id bigint,
@fldCodeSahbeCheck bigint,
@fldShomareCheck bigint,
@fldShomareHesab bigint,
@fldDateSarResid int,
@fldDatePardakht int,
@fldCodeBank int,
@fldShobe nvarchar(50),
@fldMablagh decimal
as
begin

	declare @day nvarchar(10),@month nvarchar(10),@year nvarchar(10),@fldDate nvarchar(10)
	declare @strRadif nvarchar(50),
			@jamMablagh decimal,
			@strResult nvarchar(50),
			@strResult2 nvarchar(50),
			@intShomareSanad int,
			@count int

				set @strRadif=(select fldRadif from tblCheckePardakhti where ID=@id)
	set @intShomareSanad=(select fldSanad from tblCheckePardakhti where ID=@id)
			
			update tblCheckePardakhti 
			set	
				fldCodeSahebeCheck=@fldCodeSahbeCheck,
				fldShomareCheck =@fldShomareCheck,
				fldShomareHesab =@fldShomareHesab,
				fldDateSarResid =@fldDateSarResid,
				fldDatePardakht =@fldDatePardakht,
				fldCodeBank =@fldCodeBank,
				fldShobe =@fldShobe,
				fldMablagh =@fldMablagh,
				fldShomarePardakht=0
			where ID =@id 

			set @day=(SUBSTRING(CONVERT(nvarchar, @fldDatePardakht), 7, 2))
			set @month=(SUBSTRING(CONVERT(nvarchar, @fldDatePardakht), 5, 2))
			set @year=(SUBSTRING(CONVERT(nvarchar, @fldDatePardakht), 1, 4))
			set @fldDate=@fldDatePardakht--(CONVERT(int, @year+@month+@day))

			set @jamMablagh=(select sum(fldMablagh) from tblCheckePardakhti where fldShomarePardakht=0)
			update tblSodooreSanad set fldBedehkar=@jamMablagh , fldRadif=@strRadif,fldDate= @fldDate,fldDay=@day,fldMonth=@month,fldYear=@year Where fldSanad=@intShomareSanad and fldBedehkar>0 

			update tblSodooreSanad set fldCodeTafzili=@fldCodeSahbeCheck, fldBestankar=@fldMablagh ,fldDate= @fldDate,fldDay=@day,fldMonth=@month,fldYear=@year Where fldSanad=@intShomareSanad and fldRadif=@strRadif and fldBestankar>0


end
GO

-- ===============================================
-- SP: [dbo].[z180DeleteCheakEbtedaDorehPardakhti]
-- ===============================================
IF OBJECT_ID(N'dbo.z180DeleteCheakEbtedaDorehPardakhti', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z180DeleteCheakEbtedaDorehPardakhti] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[z180DeleteCheakEbtedaDorehPardakhti]
@id bigint

as
begin
	begin transaction AddRecord
		begin try

	declare @strRadif nvarchar(50),
			@jamMablagh decimal,
			@strResult nvarchar(50),
			@strResult2 nvarchar(50),
			@intShomareSanad int,
			@count int

	set @strRadif=(select fldRadif from tblCheckePardakhti where id=@id)
	set @intShomareSanad=(select fldSanad from tblCheckePardakhti where id=@id)


	delete from tblSodooreSanad where fldType='checkebtedaPardakhti' and fldRadif=@strRadif

	--delete from tblSodooreSanad Where fldSanad=@intShomareSanad and fldBestankar>0
	delete from tblCheckePardakhti
			 where id=@id
	set @count=(Select COUNT(fldShomareCheck) from tblCheckePardakhti where fldShomarePardakht=0)
	if @count>0
	begin
	set @jamMablagh=(select sum(fldMablagh) from tblCheckePardakhti where fldShomarePardakht=0)
	update tblSodooreSanad set fldBedehkar=@jamMablagh , fldRadif=@strRadif Where fldSanad=@intShomareSanad and fldBedehkar>0
	end
	else
	begin
	delete from tblSodooreSanad Where fldSanad=@intShomareSanad and fldBedehkar>0
	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

-- ===============================================
-- SP: [dbo].[z181ShowCheakPassNashode]
-- ===============================================
IF OBJECT_ID(N'dbo.z181ShowCheakPassNashode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z181ShowCheakPassNashode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[z181ShowCheakPassNashode]
@Id bigint,
@ShomareBazPas bigint
as

	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;

create table #TempShow(
id bigint,
fldRadif bigint,
fldShomareCheck bigint,
fldShomareHesab bigint,
fldCodeSahebeHesab bigint,
fldCodeSahebeCheck bigint,
fldNameSahebeCheck NVarchar(100) COLLATE Persian_100_CI_AS,
fldDateSarResid NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeBank bigint,
fldNameBank NVarchar(100) COLLATE Persian_100_CI_AS,
fldShobe NVarchar(100) COLLATE Persian_100_CI_AS,
fldMablagh decimal,
fldShomarePass bigint,
fldSanad bigint,
fldShomareBazPas bigint,
fldSanadBazPas bigint
)

 create table #TempListCodeBank(
fldCodeBank bigint,
fldNameBank NVarchar(100) COLLATE Persian_100_CI_AS,
fldInfo NVarchar(50) COLLATE Persian_100_CI_AS
)

delete #TempShow


	insert into #TempListCodeBank(fldNameBank,fldCodeBank,fldInfo)	
	 execute ShowBankeMa
		
	if (@Id>0)
	begin
	if (@ShomareBazPas=0)
	begin
		insert into #TempShow(id,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck
	,fldNameSahebeCheck,fldDateSarResid,fldCodeBank,fldNameBank
	,fldShobe,fldMablagh,fldShomarePass,fldSanad,fldShomareBazPas,fldSanadBazPas)
	
	select  tblCheckePardakhti.Id,fldShomareCheck,tblCheckePardakhti.fldShomareHesab
			,fldCodeSahebeCheck,tblTafzili.fldSharheTafzili as fldNameSahebeCheck,
			                 SUBSTRING(CONVERT(nvarchar,fldDateSarResid), 1, 4) + '/' +
						     SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 7, 2) AS fldDateSarResid
			,tblCheckePardakhti.fldCodeBank,#TempListCodeBank.fldNameBank as fldNameBank
			,tblTafzili.fldShobe,fldMablagh,fldShomarePass,fldSanad,fldShomareBazPas,fldSanadBazPas
	from tblCheckePardakhti
	inner join tblTafzili on tblCheckePardakhti.fldCodeSahebeCheck=tblTafzili.fldCodeTafzili 
	inner join #TempListCodeBank on tblCheckePardakhti.fldCodeBank=#TempListCodeBank.fldCodeBank
	where tblCheckePardakhti.ID=@Id and fldShomarePass is null and fldShomareBazPas is null

	
	end
	else
	begin
	insert into #TempShow(id,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck
	,fldNameSahebeCheck,fldDateSarResid,fldCodeBank,fldNameBank
	,fldShobe,fldMablagh,fldShomarePass,fldSanad,fldShomareBazPas,fldSanadBazPas)
	
	select  tblCheckePardakhti.Id,fldShomareCheck,tblCheckePardakhti.fldShomareHesab
			,fldCodeSahebeCheck,tblTafzili.fldSharheTafzili as fldNameSahebeCheck,
			                 SUBSTRING(CONVERT(nvarchar,fldDateSarResid), 1, 4) + '/' +
						     SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 7, 2) AS fldDateSarResid
			,tblCheckePardakhti.fldCodeBank,#TempListCodeBank.fldNameBank as fldNameBank
			,tblTafzili.fldShobe,fldMablagh,fldShomarePass,fldSanad,fldShomareBazPas,fldSanadBazPas
	from tblCheckePardakhti
	inner join tblTafzili on tblCheckePardakhti.fldCodeSahebeCheck=tblTafzili.fldCodeTafzili 
	inner join #TempListCodeBank on tblCheckePardakhti.fldCodeBank=#TempListCodeBank.fldCodeBank
	where  fldShomareBazPas = @ShomareBazPas and tblCheckePardakhti.ID=@Id

	end
	end
	else
	begin		 
if (@ShomareBazPas=0)
	begin
	insert into #TempShow(id,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck
	,fldNameSahebeCheck,fldDateSarResid,fldCodeBank,fldNameBank
	,fldShobe,fldMablagh,fldShomarePass,fldSanad,fldShomareBazPas,fldSanadBazPas)
	
	select  tblCheckePardakhti.Id,fldShomareCheck,tblCheckePardakhti.fldShomareHesab
			,fldCodeSahebeCheck,tblTafzili.fldSharheTafzili as fldNameSahebeCheck,
			                 SUBSTRING(CONVERT(nvarchar,fldDateSarResid), 1, 4) + '/' +
						     SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 7, 2) AS fldDateSarResid
			,tblCheckePardakhti.fldCodeBank,#TempListCodeBank.fldNameBank as fldNameBank
			,tblTafzili.fldShobe,fldMablagh,fldShomarePass,fldSanad,fldShomareBazPas,fldSanadBazPas
	from tblCheckePardakhti
	inner join tblTafzili on tblCheckePardakhti.fldCodeSahebeCheck=tblTafzili.fldCodeTafzili 
	inner join #TempListCodeBank on tblCheckePardakhti.fldCodeBank=#TempListCodeBank.fldCodeBank
	where fldShomarePass is null and fldShomareBazPas is null
	end
	else
		begin
	insert into #TempShow(id,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck
	,fldNameSahebeCheck,fldDateSarResid,fldCodeBank,fldNameBank
	,fldShobe,fldMablagh,fldShomarePass,fldSanad,fldShomareBazPas,fldSanadBazPas)
	
select  tblCheckePardakhti.Id,fldShomareCheck,tblCheckePardakhti.fldShomareHesab
			,fldCodeSahebeCheck,tblTafzili.fldSharheTafzili as fldNameSahebeCheck,
			                 SUBSTRING(CONVERT(nvarchar,fldDateSarResid), 1, 4) + '/' +
						     SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 5, 2) + '/' + 
							 SUBSTRING(CONVERT(nvarchar, fldDateSarResid), 7, 2) AS fldDateSarResid
			,tblCheckePardakhti.fldCodeBank,#TempListCodeBank.fldNameBank as fldNameBank
			,tblTafzili.fldShobe,fldMablagh,fldShomarePass,fldSanad,fldShomareBazPas,fldSanadBazPas
	from tblCheckePardakhti
	inner join tblTafzili on tblCheckePardakhti.fldCodeSahebeCheck=tblTafzili.fldCodeTafzili 
	inner join #TempListCodeBank on tblCheckePardakhti.fldCodeBank=#TempListCodeBank.fldCodeBank
	where fldShomareBazPas=@ShomareBazPas and fldShomarePass is null and fldShomareBazPas is not null
	end
end
	select ROW_NUMBER() OVER(ORDER BY Id) as fldRadif,id,fldShomareCheck,fldShomareHesab,fldCodeSahebeCheck,fldNameSahebeCheck,fldDateSarResid,fldCodeBank,fldNameBank,fldShobe,fldMablagh,fldShomarePass,fldSanad,fldShomareBazPas,fldSanadBazPas from #TempShow
end
GO

-- ===============================================
-- SP: [dbo].[z182UpdateCheakBazPas]
-- ===============================================
IF OBJECT_ID(N'dbo.z182UpdateCheakBazPas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z182UpdateCheakBazPas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z182UpdateCheakBazPas]
	@bazsabt int,
	@Id bigint,
	@ShomareBazPas bigint,
	@SanadBazPas bigint,
	@fldSumMablagh decimal,
	@Date bigint,
	@Sharh Nvarchar(200),
	@type nvarchar(50),
	@vaziat nvarchar(50),
	@tblTemp dtCheckBazPasShode  readonly,
	@strResult1 nvarchar(30) output,
	@strResult2 nvarchar(100) output
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END

 
begin

begin transaction AddRecord
		begin try


		 	--select * from tblsodooresanad where fldsanad=38547
	--select * from tblcheckepardakhti where fldSanadBazPas=38806
 --  --select * from tblcheckepardakhti where fldShomareCheck=590536 or fldShomareCheck=511132 or fldShomareCheck=494781
 --  delete tblsodooresanad WHERE        (fldType = 'bazpascheckekhodeman')
 --select * from tblcheckepardakhti where fldshomarebazpas=191
 --select * from tbltest5
	if(@type='Add')
	begin


		declare @MaxShomareBazPas bigint
		declare @MaxSanadBazPas bigint

		Set @MaxShomareBazPas=(select Max(fldShomareBazPas) from tblCheckePardakhti)
		Set @MaxSanadBazPas=(select Max(fldSanadBazPas) from tblCheckePardakhti)
		
		if isnumeric(@MaxShomareBazPas)=0
			set @MaxShomareBazPas=1
		else
			set @MaxShomareBazPas=@MaxShomareBazPas+1

		if (@MaxShomareBazPas<>@ShomareBazPas)
			set @MaxSanadBazPas=@ShomareBazPas

		if isnumeric(@MaxSanadBazPas)=0
			set @MaxSanadBazPas=1
		else
			set @MaxSanadBazPas=@MaxSanadBazPas+1

		if (@MaxSanadBazPas<>@SanadBazPas)
			set @MaxSanadBazPas=@SanadBazPas

	--Declare Info
		DECLARE @counter bigint = 1,
				@count bigint=(Select COUNT(id) from @tblTemp),
				@fldId bigint,
				@ShomareSanad bigint,
				@fldCodeTafzili bigint,
				@fldSarheTafzili nvarchar(50),
				@fldMablagh decimal,
				@fldShomareCheck bigint,
				@lngDate bigint,
				@day nvarchar(50), 
				@month nvarchar(50),
				@year nvarchar(50) 

		WHILE @counter <= @count
		BEGIN
		--Set Info
			--set @fldId=(select id from @tblTemp where fldRadif=@counter)
			set @fldId=(select top(1)id from @tblTemp )
			--INSERT INTO tblTest2
   --                 (name)
			--VALUES        ('a' + convert(nvarchar, @fldId))
			set @fldCodeTafzili=(select top(1)fldCodeSahebeCheck from @tblTemp )
			set @fldMablagh=(select top(1)fldMablagh from @tblTemp )
			set @fldShomareCheck=(select top(1)fldShomareCheck from @tblTemp )
			set @lngDate=@Date
			Set @year=SUBSTRING(CONVERT(nvarchar,@Date), 1, 4)
			Set @month=SUBSTRING(CONVERT(nvarchar,@Date), 5, 2)
			Set @day=SUBSTRING(CONVERT(nvarchar,@Date), 7, 2)
		
				--update BazPas
					--select * from tblcheckepardakhti where fldShomareCheck=9922320
			if(@vaziat='update')
				begin
					Update tblCheckePardakhti Set fldShomareBazPas=@ShomareBazPas,fldDateBazPas=@Date,fldSharhBazPas=@Sharh,fldSanadBazPas=@SanadBazPas
					where ID=@fldId
					--INSERT INTO tblTest2
     --                    (name)
					--VALUES        ('b' + convert(nvarchar, @fldId))
				end
		

				SET @counter = @counter + 1;
		END

			declare @CountCheck bigint,
			@fldMablaghCheck decimal,
			@fldSharh nvarchar(100),
			@TooleKol bigint,
			@Toolemoin bigint,

			@CodeMoin1 nvarchar(100),
			@CodeKolkham1 nvarchar(10),
			@CodeMoinKham1 nvarchar(10),

			@CodeMoin2 nvarchar(100),
			@CodeKolkham2 nvarchar(10),
			@CodeMoinKham2 nvarchar(10)



			execute  ToolePaye 'kol',@TooleKol output
			execute  ToolePaye 'moin',@Toolemoin output
			execute codemoinhesab 'checkpardakhti' ,@CodeMoin1 output
			set @CodeKolkham1 =substring(@CodeMoin1, 1, @TooleKol)
			set @CodeMoinKham1 =substring(@CodeMoin1,@TooleKol+1,@Toolemoin)

			execute  ToolePaye 'kol',@TooleKol output
			execute  ToolePaye 'moin',@Toolemoin output
			execute codemoinhesab 'hesabhayepardakhtani' ,@CodeMoin2 output
			set @CodeKolkham2 =substring(@CodeMoin2, 1, @TooleKol)
			set @CodeMoinKham2 =substring(@CodeMoin2,@TooleKol+1,@Toolemoin)


			Set @CountCheck=(Select Count(ID) from tblSodooreSanad where fldSanad=@SanadBazPas)
			Set @fldSharh=N'بازپس گیری چک شماره '+ Convert(varchar, @fldShomareCheck)
	--check Sanad
			--if(@CountCheck=0)
				--begin
					--Insert Sanad	

			if(@vaziat='insert')
				begin
					if @bazsabt=1--یعنی باز ثبت
						begin
							execute insertSanadLast  @CodeKolkham1,@CodeMoinKham1,@CodeMoin1,@fldCodeTafzili,'1',@fldSumMablagh,0,1,@lngDate,@fldSharh,@day,@month,@year,'bazpascheckekhodeman',Null,@SanadBazPas ;
							execute insertSanadLast @CodeKolkham2,@CodeMoinKham2,@CodeMoin2,@fldCodeTafzili,'1',0,@fldSumMablagh,2,@lngDate,@fldSharh,@day,@month,@year,'bazpascheckekhodeman',Null,@SanadBazPas;

							Update tblCheckePardakhti Set fldShomareBazPas=@ShomareBazPas,fldDateBazPas=@Date,fldSharhBazPas=@Sharh,fldSanadBazPas=@SanadBazPas	where fldShomareBazPas=@ShomareBazPas				
						end
					else
						begin
							execute insertSanadFirst  @CodeKolkham1,@CodeMoinKham1,@CodeMoin1,@fldCodeTafzili,'1',@fldSumMablagh,0,1,@lngDate,@fldSharh,@day,@month,@year,'bazpascheckekhodeman',Null,@ShomareSanad output;
							execute insertSanadLast @CodeKolkham2,@CodeMoinKham2,@CodeMoin2,@fldCodeTafzili,'1',0,@fldSumMablagh,2,@lngDate,@fldSharh,@day,@month,@year,'bazpascheckekhodeman',Null,@ShomareSanad;

							Update tblCheckePardakhti Set fldShomareBazPas=@MaxShomareBazPas,fldDateBazPas=@Date,fldSharhBazPas=@Sharh,fldSanadBazPas=@ShomareSanad
							where ID=@fldId
						end 


					
				end
			else if (@vaziat='update')
				begin
					delete from tblsodooresanad where fldsanad=@SanadBazPas
					execute insertSanadLast @CodeKolkham1,@CodeMoinKham1,@CodeMoin1,@fldCodeTafzili,'1',@fldSumMablagh,0,1,@lngDate,@fldSharh,@day,@month,@year,'bazpascheckekhodeman',Null,@SanadBazPas ;	
					execute insertSanadLast @CodeKolkham2,@CodeMoinKham2,@CodeMoin2,@fldCodeTafzili,'1',0,@fldSumMablagh,2,@lngDate,@fldSharh,@day,@month,@year,'bazpascheckekhodeman',Null,@SanadBazPas;

				end
			--else
			--	begin 
			--		--Update Sanad
			--		Set @fldMablaghCheck=(Select fldBedehkar from tblSodooreSanad where fldSanad=@SanadBazPas and fldBestankar=0)
			--		update tblSodooreSanad Set fldBedehkar=@fldMablaghCheck+@fldSumMablagh where fldSanad=@SanadBazPas and fldBestankar=0
			--		update tblSodooreSanad Set fldBestankar=@fldMablaghCheck+@fldSumMablagh where fldSanad=@SanadBazPas and fldBedehkar=0
			--	end

	end
	else if(@type='Remove')
	begin
	--Declare Info
		DECLARE @counter2 bigint = 1,
			@count2 bigint=(Select COUNT(id) from @tblTemp),
			@fldId2 bigint,
			@ShomareSanad2 bigint,
			@fldCodeTafzili2 bigint,
			@fldSarheTafzili2 nvarchar(50),
			@fldMablagh2 decimal,
			@lngDate2 bigint,
			@day2 nvarchar(50), 
			@month2 nvarchar(50),
			@year2 nvarchar(50) 

		WHILE @counter2 <= @count2
			BEGIN
			--Set Info
			set @fldId=(select id from @tblTemp where fldRadif=@counter2)
			set @fldCodeTafzili=(select fldCodeSahebeCheck from @tblTemp where fldRadif=@counter2)
			set @fldMablagh=(select fldMablagh from @tblTemp where fldRadif=@counter2)
			set @lngDate=@Date
			Set @year=SUBSTRING(CONVERT(nvarchar,@Date), 1, 4)
			Set @month=SUBSTRING(CONVERT(nvarchar,@Date), 5, 2)
			Set @day=SUBSTRING(CONVERT(nvarchar,@Date), 7, 2)
		
				--update BazPas
		
			Update tblCheckePardakhti Set fldShomareBazPas=NULL,fldDateBazPas=NULL,fldSharhBazPas=NULL,fldSanadBazPas=NULL
			where ID=@fldId

			SET @counter2 = @counter2 + 1;
		END
	
			--UPDATE Sanad	
		if (@fldSumMablagh=0)
			begin
				Update tblCheckePardakhti Set fldShomareBazPas=NULL,fldDateBazPas=NULL,fldSharhBazPas=NULL,fldSanadBazPas=NULL
				where fldShomareBazPas=@ShomareBazPas
				delete tblSodooreSanad where fldSanad=@SanadBazPas
			end
		else
			begin
				set @fldShomareCheck=(select top(1) fldShomareCheck from tblCheckePardakhti where fldShomareBazPas=@SanadBazPas )--(select top(1) fldShomareCheck from @tblTemp)
				Set @fldSharh=N'بازپس گیری چک شماره '+ Convert(varchar, @fldShomareCheck)
				update tblSodooreSanad set fldBedehkar=@fldSumMablagh,fldsharh=@fldSharh where fldBestankar=0 and fldSanad=@SanadBazPas
				update tblSodooreSanad set fldBestankar=@fldSumMablagh,fldsharh=@fldSharh where fldBedehkar=0 and fldSanad=@SanadBazPas
			end


		end

	commit transaction AddRecord;
		
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult1='error'
			    set @strResult2=(SELECT Convert(varchar,Error_Line()) +  ERROR_MESSAGE() AS ErrorNumber) 
				rollback transaction AddRecord;
			end
		end catch

END
GO

-- ===============================================
-- SP: [dbo].[z183DeleteCheakBazPas]
-- ===============================================
IF OBJECT_ID(N'dbo.z183DeleteCheakBazPas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z183DeleteCheakBazPas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z183DeleteCheakBazPas]
	@Id bigint,
	@ShomareBazPas bigint,
	@SanadBazPas bigint,
	@strResult1 nvarchar(30) output,
	@strResult2 bigint output
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END

 
begin

begin transaction AddRecord
		begin try

	
	
	Update tblCheckePardakhti Set fldShomareBazPas=NULL,fldDateBazPas=NULL,fldSharhBazPas=NULL,fldSanadBazPas=NULL
	where fldShomareBazPas=@ShomareBazPas

	delete tblSodooreSanad where fldSanad=@SanadBazPas 

	

	commit transaction AddRecord;
		
		end try
		begin catch
			if @@TranCount>0
			begin
				set @strResult1='error'
			    set @strResult2=(SELECT Error_Line() AS ErrorNumber)
				rollback transaction AddRecord;
			end
		end catch

END
GO

-- ===============================================
-- SP: [dbo].[z184ShowListeAghsat]
-- ===============================================
IF OBJECT_ID(N'dbo.z184ShowListeAghsat', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z184ShowListeAghsat] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z184ShowListeAghsat] 
	@CodeTafzili nvarchar(10),
	@ShomareVam bigint,
	@DateFrom bigint,
	@DateTo bigint,
	@Model int
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN


CREATE TABLE #tmpDaryaftTasfie2(
	[fldRadif] [bigint]  null,
	[fldShomareVam] [bigint]  null,
	[fldShomareGhest] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeTafzili] [nvarchar](10) COLLATE Persian_100_CI_AS,
	[fldMablagheMande][bigint],	
	[fldMablagheDaryaftiJari] [bigint],
	[fldDateSarResid][bigint],
	[ShomareDaryaft][bigint],
	[fldModel] int,
	[fldOnvaneModel] [nvarchar](100) COLLATE Persian_100_CI_AS,
	[fldSharheModel] [nvarchar](250) COLLATE Persian_100_CI_AS

	)

		declare @Model1 nvarchar(100),@Model2 nvarchar(100),@Model3 nvarchar(100)
		if (@ShomareVam=0)
		begin
			insert into #tmpDaryaftTasfie2
		(fldRadif,fldShomareVam,fldShomareGhest,SumDaryafti,fldCodeTafzili,fldMablagheMande,fldDateSarResid)
		Select ROW_NUMBER() OVER(ORDER BY tblDaftarcheAghsat.Id) as fldRadif,  tblDaftarcheAghsat.fldShomareVam,fldRadif,0,fldCodeTafzili, tblDaftarcheAghsat.fldMablaghGhest,fldDateSarResid
			from tblDaftarcheAghsat
			inner join tblVamInfo
			on tblDaftarcheAghsat.fldShomareVam =tblVamInfo.fldShomareVam
			where fldCodeTafzili = @CodeTafzili 
		end
		else
		begin
			insert into #tmpDaryaftTasfie2
		(fldRadif,fldShomareVam,fldShomareGhest,SumDaryafti,fldCodeTafzili,fldMablagheMande,fldDateSarResid)
		Select ROW_NUMBER() OVER(ORDER BY tblDaftarcheAghsat.Id) as fldRadif, tblDaftarcheAghsat.fldShomareVam,fldRadif,0,fldCodeTafzili, tblDaftarcheAghsat.fldMablaghGhest,fldDateSarResid
			from tblDaftarcheAghsat
			inner join tblVamInfo
			on tblDaftarcheAghsat.fldShomareVam =tblVamInfo.fldShomareVam
			where fldCodeTafzili = @CodeTafzili and tblDaftarcheAghsat.fldShomareVam=@ShomareVam
		end

	update #tmpDaryaftTasfie2
		set SumDaryafti=tbl1.sumDaryafti from		
		(Select fldShomareVam,fldShomareGhest, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfieVam group by fldShomareVam,fldShomareGhest ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie2.fldShomareFactor) as tbl1
		where #tmpDaryaftTasfie2.fldShomareVam=tbl1.fldShomareVam and  #tmpDaryaftTasfie2.fldShomareGhest=tbl1.fldShomareGhest


		update #tmpDaryaftTasfie2 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
			(Select fldShomareVam,fldShomareGhest, fldMablagh from tblRizeTasfieVam) as tbl2
			where tbl2.fldShomareVam=#tmpDaryaftTasfie2.fldShomareVam and tbl2.fldShomareGhest=#tmpDaryaftTasfie2.fldShomareGhest
	

	update #tmpDaryaftTasfie2 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null
	

	update  #tmpDaryaftTasfie2 set fldModel=tblVamModel.fldModel from tblVamModel where tblVamModel.fldShomareVam=#tmpDaryaftTasfie2.fldShomareVam
	if @Model<>-1
		begin			
			delete #tmpDaryaftTasfie2 where fldModel<>(@model)
			--delete #tmpDaryaftTasfie2 where fldShomareVam not in (select fldShomareVam from tblVamModel where fldModel=@model)
		end

	update #tmpDaryaftTasfie2 set fldSharheModel=tblVamModel.fldSharheModel from tblVamModel where tblVamModel.fldShomareVam=#tmpDaryaftTasfie2.fldShomareVam
    execute  ShowTanzimatNew 'sharhemodel1', @Model1 output
	execute  ShowTanzimatNew 'sharhemodel2', @Model2 output
	execute  ShowTanzimatNew 'sharhemodel3', @Model3 output

	update #tmpDaryaftTasfie2 set fldOnvaneModel=@Model1 where fldModel=1
	update #tmpDaryaftTasfie2 set fldOnvaneModel=@Model2 where fldModel=2
	update #tmpDaryaftTasfie2 set fldOnvaneModel=@Model3 where fldModel=3

	Select fldRadif, fldShomareVam,fldShomareGhest,SumDaryafti,fldMablagheMande,fldMablagheDaryaftiJari,
		substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,fldModel,fldOnvaneModel,fldSharheModel
		from #tmpDaryaftTasfie2
			where fldMablagheMande>SumDaryafti or fldMablagheDaryaftiJari>0 
		order by fldRadif

END
GO

-- ===============================================
-- SP: [dbo].[z185ShowListeJameAghsat]
-- ===============================================
IF OBJECT_ID(N'dbo.z185ShowListeJameAghsat', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z185ShowListeJameAghsat] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z185ShowListeJameAghsat] 
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@Model int
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN
CREATE TABLE #tmpDaryaftTasfie2(
	[fldRadif] [bigint]  null,
	[fldShomareVam] [bigint]  null,
	[fldShomareGhest] [bigint]  null,
	[SumDaryafti] [bigint] null,
	[fldCodeGroup] [bigint] null,
	[fldNameGroup] [nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldCodeTafzili] [bigint] null,
	[fldSharhTafzili] [nvarchar](200) COLLATE Persian_100_CI_AS,
	[fldDate][bigint],
	[fldMablagheMande][bigint],	
	[fldMablagheDaryaftiJari] [bigint],
	[fldDateSarResid][bigint],
	[ShomareDaryaft][bigint],
	[fldModel] int,
	[fldOnvaneModel] [nvarchar](100) COLLATE Persian_100_CI_AS,
	[fldSharheModel] [nvarchar](250) COLLATE Persian_100_CI_AS
	)

	declare @Model1 nvarchar(100),@Model2 nvarchar(100),@Model3 nvarchar(100)

	insert into #tmpDaryaftTasfie2
	(fldShomareVam,fldShomareGhest,SumDaryafti,fldCodeGroup,fldCodeTafzili,fldDate,fldMablagheMande,fldDateSarResid)
	Select   tblDaftarcheAghsat.fldShomareVam,fldRadif,0 as SumDaryafti,0 as fldCodeGroup,fldCodeTafzili, tblVamInfo.fldDate,tblDaftarcheAghsat.fldMablaghGhest,fldDateSarResid
	from tblDaftarcheAghsat
	inner join tblVamInfo
	on tblDaftarcheAghsat.fldShomareVam =tblVamInfo.fldShomareVam
		
	update #tmpDaryaftTasfie2
	set SumDaryafti=tbl1.sumDaryafti from		
	(Select fldShomareVam,fldShomareGhest, isnull(Sum(fldMablagh),0) as sumDaryafti from tblRizeTasfieVam group by fldShomareVam,fldShomareGhest ) as tbl1 -- Where fldShomareFactor=#tmpDaryaftTasfie2.fldShomareFactor) as tbl1
	where #tmpDaryaftTasfie2.fldShomareVam=tbl1.fldShomareVam and  #tmpDaryaftTasfie2.fldShomareGhest=tbl1.fldShomareGhest

	update #tmpDaryaftTasfie2 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	(Select fldShomareVam,fldShomareGhest, fldMablagh from tblRizeTasfieVam) as tbl2
	where tbl2.fldShomareVam=#tmpDaryaftTasfie2.fldShomareVam and tbl2.fldShomareGhest=#tmpDaryaftTasfie2.fldShomareGhest
	
	update #tmpDaryaftTasfie2 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null

	update #tmpDaryaftTasfie2 set fldCodeGroup=tblTafzili.fldCodeGroup from #tmpDaryaftTasfie2
	inner join tblTafzili on #tmpDaryaftTasfie2.fldCodeTafzili=tblTafzili.fldCodeTafzili

	update #tmpDaryaftTasfie2 set fldNameGroup=tblGroupAshkhas.fldGroupName from #tmpDaryaftTasfie2
	inner join tblGroupAshkhas on #tmpDaryaftTasfie2.fldCodeGroup=tblGroupAshkhas.fldGroupId

	update #tmpDaryaftTasfie2 set fldSharhTafzili=tblTafzili.fldSharheTafzili from #tmpDaryaftTasfie2
	inner join tblTafzili on #tmpDaryaftTasfie2.fldCodeTafzili=tblTafzili.fldCodeTafzili

	if @ListAshkhas <>''
	   begin
			 declare @StrDeleteAshkhas varchar(5000)
			 set  @StrDeleteAshkhas='delete from #tmpDaryaftTasfie2 
			 where '+ @ListAshkhas + ''
			execute(@StrDeleteAshkhas)
		end


		if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #tmpDaryaftTasfie2 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end

	update  #tmpDaryaftTasfie2 set fldModel=tblVamModel.fldModel from tblVamModel where tblVamModel.fldShomareVam=#tmpDaryaftTasfie2.fldShomareVam
	if @Model<>-1
		begin			
			delete #tmpDaryaftTasfie2 where fldModel<>(@model)
			--delete #tmpDaryaftTasfie2 where fldShomareVam not in (select fldShomareVam from tblVamModel where fldModel=@model)
		end

	update #tmpDaryaftTasfie2 set fldSharheModel=tblVamModel.fldSharheModel from tblVamModel where tblVamModel.fldShomareVam=#tmpDaryaftTasfie2.fldShomareVam
    execute  ShowTanzimatNew 'sharhemodel1', @Model1 output
	execute  ShowTanzimatNew 'sharhemodel2', @Model2 output
	execute  ShowTanzimatNew 'sharhemodel3', @Model3 output

	update #tmpDaryaftTasfie2 set fldOnvaneModel=@Model1 where fldModel=1
	update #tmpDaryaftTasfie2 set fldOnvaneModel=@Model2 where fldModel=2
	update #tmpDaryaftTasfie2 set fldOnvaneModel=@Model3 where fldModel=3

	Select  fldShomareVam,fldShomareGhest,SumDaryafti,fldCodeGroup,fldNameGroup,fldCodeTafzili,fldSharhTafzili,fldMablagheMande,fldMablagheDaryaftiJari,
	substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate,
		substring(convert(nvarchar(10),fldDateSarResid),0,5) +'/' +substring(convert(nvarchar(10),fldDateSarResid),5,2) + '/' + substring(convert(nvarchar(10),fldDateSarResid),7,2) as fldDateSarResid,fldModel,fldOnvaneModel,fldSharheModel
		from #tmpDaryaftTasfie2
			where fldMablagheMande>SumDaryafti or fldMablagheDaryaftiJari>0 
		group by fldShomareVam,fldShomareGhest,SumDaryafti,fldCodeGroup,fldNameGroup,fldCodeTafzili,fldSharhTafzili,fldMablagheMande,fldMablagheDaryaftiJari,fldDate,fldDateSarResid,fldModel,fldOnvaneModel,fldSharheModel

END
GO

-- ===============================================
-- SP: [dbo].[z186ShowListeAghsatMoavaghe]
-- ===============================================
IF OBJECT_ID(N'dbo.z186ShowListeAghsatMoavaghe', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z186ShowListeAghsatMoavaghe] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
Alter PROCEDURE [dbo].[z186ShowListeAghsatMoavaghe] 
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@TaDateSarResid bigint
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN

CREATE TABLE #tmpDaryaftTasfie1(
	[fldRadif] [bigint]  null,
	[fldShomareVam] [bigint]  null,
	[fldTedadAghsat] [bigint]  null,
	[fldCodeGroup] [bigint] null,
	[fldNameGroup] [nvarchar](200) COLLATE Persian_100_CI_AS,
	[fldCodeTafzili] [bigint] null,
	[fldSharhTafzili] [nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldDate][nvarchar](18) COLLATE Persian_100_CI_AS,
	[fldMablagheGhest][decimal],
	[fldMablagheMande][decimal],		
	[fldMablagheDaryaftiJari] [decimal],
	[fldDateSarResid] [bigint] null,
	[fldShomareGhest] [bigint] null
	)

	CREATE TABLE #tmpDaryaftTasfie2(
	[fldRadif] [bigint]  null,
	[fldShomareVam] [bigint]  null,
	[fldTedadAghsat] [bigint]  null,
	[fldCodeGroup] [bigint] null,
	[fldNameGroup] [nvarchar](200) COLLATE Persian_100_CI_AS,
	[fldCodeTafzili] [bigint] null,
	[fldSharhTafzili] [nvarchar](80) COLLATE Persian_100_CI_AS,
	[fldDate][bigint],
	[fldMablagheGhest][decimal],
	[fldMablagheMande][decimal],		
	[fldMablagheDaryaftiJari] [decimal],
	[fldDateSarResid] [bigint] null,
	[fldShomareGhest] [bigint] null
	)

	CREATE TABLE #tmpTedadAghsat(
	[fldShomareVam] [bigint]  null,
	[fldTedadAghsat] [bigint]  null
	)

	insert into #tmpDaryaftTasfie2
	(fldShomareVam,fldTedadAghsat ,fldCodeGroup,fldCodeTafzili,fldDate,fldMablagheGhest,fldMablagheMande,fldMablagheDaryaftiJari,fldDateSarResid,fldShomareGhest)
	Select tblDaftarcheAghsat.fldShomareVam,0 as fldTedadAghsat,0 as fldCodeGroup,fldCodeTafzili,fldDate,tblDaftarcheAghsat.fldMablaghGhest,0 as fldMablagheMande,0 as fldMablagheDaryaftiJari,tblDaftarcheAghsat.fldDateSarResid,tblDaftarcheAghsat.fldRadif as fldShomareGhest
	from tblDaftarcheAghsat
	inner join tblVamInfo
	on tblDaftarcheAghsat.fldShomareVam =tblVamInfo.fldShomareVam 
	where fldDateSarResid<=@TaDateSarResid
		

	
	update #tmpDaryaftTasfie2 set fldMablagheDaryaftiJari=tbl2.fldMablagh from
	(Select fldShomareVam,fldShomareGhest,sum(fldMablagh) as fldMablagh from tblRizeTasfieVam group by fldShomareVam,fldShomareGhest ) as tbl2
	where tbl2.fldShomareVam=#tmpDaryaftTasfie2.fldShomareVam and #tmpDaryaftTasfie2.fldShomareGhest=tbl2.fldShomareGhest

	--select * from #tmpDaryaftTasfie2
	
	--update #tmpDaryaftTasfie2 set fldMablagheDaryaftiJari=0 where fldMablagheDaryaftiJari is null

	update #tmpDaryaftTasfie2 set fldMablagheMande=(tbl2.fldMablagheGhest-tbl2.fldMablagheDaryaftiJari) from
	(Select fldShomareVam,fldShomareGhest,fldMablagheGhest,fldMablagheDaryaftiJari from #tmpDaryaftTasfie2
	) as tbl2
	where tbl2.fldShomareVam=#tmpDaryaftTasfie2.fldShomareVam and tbl2.fldShomareGhest=#tmpDaryaftTasfie2.fldShomareGhest

	update #tmpDaryaftTasfie2 set fldCodeGroup=tblTafzili.fldCodeGroup from #tmpDaryaftTasfie2
	inner join tblTafzili on #tmpDaryaftTasfie2.fldCodeTafzili=tblTafzili.fldCodeTafzili

	update #tmpDaryaftTasfie2 set fldNameGroup=tblGroupAshkhas.fldGroupName from #tmpDaryaftTasfie2
	inner join tblGroupAshkhas on #tmpDaryaftTasfie2.fldCodeGroup=tblGroupAshkhas.fldGroupId



	update #tmpDaryaftTasfie2 set fldSharhTafzili=tblTafzili.fldSharheTafzili from #tmpDaryaftTasfie2
	inner join tblTafzili on #tmpDaryaftTasfie2.fldCodeTafzili=tblTafzili.fldCodeTafzili

	insert into #tmpTedadAghsat(fldShomareVam,fldTedadAghsat)
	select fldShomareVam,COUNT(*) fldTedadAghsat from #tmpDaryaftTasfie2 where fldMablagheMande>0
	group by fldShomareVam



	update #tmpDaryaftTasfie2 set fldTedadAghsat=tbl2.fldTedadAghsat from
	(Select fldShomareVam,fldTedadAghsat from #tmpTedadAghsat) as tbl2
	where tbl2.fldShomareVam=#tmpDaryaftTasfie2.fldShomareVam 
	  

	if @ListAshkhas <>''
	   begin
			 declare @StrDeleteAshkhas varchar(5000)
			 set  @StrDeleteAshkhas='delete from #tmpDaryaftTasfie2 
			 where '+ @ListAshkhas + ''
			execute(@StrDeleteAshkhas)
		end


		if @ListGroupAshkhas <>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #tmpDaryaftTasfie2 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end


		insert into #tmpDaryaftTasfie1
	(fldShomareVam,fldTedadAghsat ,fldCodeGroup,fldNameGroup,fldCodeTafzili,fldSharhTafzili,fldMablagheGhest,fldMablagheMande,fldMablagheDaryaftiJari,fldDate)
		Select  fldShomareVam,#tmpDaryaftTasfie2.fldTedadAghsat,fldCodeGroup,fldNameGroup,fldCodeTafzili,fldSharhTafzili,fldMablagheGhest,fldMablagheMande*fldTedadAghsat   as fldMablagheMande,fldMablagheDaryaftiJari,
		substring(convert(nvarchar(10),fldDate),0,5) +'/' +substring(convert(nvarchar(10),fldDate),5,2) + '/' + substring(convert(nvarchar(10),fldDate),7,2) as fldDate
		from #tmpDaryaftTasfie2 
		where    #tmpDaryaftTasfie2.fldMablagheMande>0 
		group by fldShomareVam,#tmpDaryaftTasfie2.fldTedadAghsat,fldCodeGroup,fldNameGroup,fldCodeTafzili,fldSharhTafzili,fldMablagheGhest,fldMablagheMande,fldMablagheDaryaftiJari,fldDate

		update #tmpDaryaftTasfie1 set fldMablagheMande=tbl2.fldMablagheMande from
		 (Select fldShomareVam,fldMablagheMande,fldMablagheDaryaftiJari from #tmpDaryaftTasfie1 where fldMablagheDaryaftiJari=0) as tbl2	
		where tbl2.fldShomareVam=#tmpDaryaftTasfie1.fldShomareVam and #tmpDaryaftTasfie1.fldMablagheDaryaftiJari>0

		update #tmpDaryaftTasfie1 set fldMablagheMande=(tbl2.fldMablagheGhest*tbl2.fldTedadAghsat)-tbl2.fldMablagheDaryaftiJari from
		 (Select fldShomareVam,fldMablagheGhest,fldMablagheDaryaftiJari,fldTedadAghsat from #tmpDaryaftTasfie1 where fldMablagheDaryaftiJari>0) as tbl2	
		where tbl2.fldShomareVam=#tmpDaryaftTasfie1.fldShomareVam and #tmpDaryaftTasfie1.fldMablagheDaryaftiJari>0

		update #tmpDaryaftTasfie1 set fldMablagheMande=tbl2.fldMablagheMande, fldMablagheDaryaftiJari=tbl2.fldMablagheDaryaftiJari from
		 (Select fldShomareVam,fldMablagheMande,fldMablagheDaryaftiJari from #tmpDaryaftTasfie1 where fldMablagheDaryaftiJari>0) as tbl2	
		where tbl2.fldShomareVam=#tmpDaryaftTasfie1.fldShomareVam and #tmpDaryaftTasfie1.fldMablagheDaryaftiJari=0
	

	select distinct fldShomareVam,fldTedadAghsat ,fldCodeGroup,fldNameGroup,fldCodeTafzili
	,fldSharhTafzili,fldMablagheGhest,fldMablagheMande
	,fldMablagheDaryaftiJari,fldDate from #tmpDaryaftTasfie1
	
		
		--delete #tmpDaryaftTasfie1
		--delete #tmpDaryaftTasfie2
		--delete #tmpTedadAghsat
END
GO

-- ===============================================
-- SP: [dbo].[z188TransformOldTafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.z188TransformOldTafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z188TransformOldTafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[z188TransformOldTafzili] 
  @dtOldTafzili dtOldTafzili  readonly
AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END
BEGIN




	insert into tblTafzili(fldCodeTafzili,fldSharheTafzili,fldNoeHesab,fldNoe,fldCodeNoe,fldCodeGroup)
        select RTRIM(fldCodeTafzili),RTRIM(fldSharheTafzili),RTRIM(fldNoeHesab),RTRIM(fldNoe),RTRIM(fldCodeNoe),'100' from @dtOldTafzili
	

		
	

		

END
GO

-- ===============================================
-- SP: [dbo].[z189ShowList_ReportAmalkardeVisitor2]
-- ===============================================
IF OBJECT_ID(N'dbo.z189ShowList_ReportAmalkardeVisitor2', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z189ShowList_ReportAmalkardeVisitor2] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z189ShowList_ReportAmalkardeVisitor2]
	@ListAshkhas varchar(5000)=null,
	@ListGroupAshkhas varchar(5000)=null,
	@ListVisitor varchar(5000)=null,
	@DateAz varchar(50),
	@DateTa varchar(50)
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 


create table #TempShow(
fldCodeTafzili bigint,
fldSharhTafzili NVarchar(100) COLLATE Persian_100_CI_AS,
fldTedadForoosh bigint,
fldMablaghForoosh decimal,
fldCodeGroupAshkhas bigint,
fldNameGroupAshkhas NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeVisitor bigint,
fldNameVisitor NVarchar(100) COLLATE Persian_100_CI_AS,
)

create table #TempSumForoosh(
fldCodeTafzili bigint,
fldMablaghForoosh decimal,
fldVasete bigint

)

create table #TempCountForoosh(
fldShomareFactor bigint,
fldCodeTafsili bigint,
fldCodeVasete bigint
)



	delete from #TempShow
	delete from #TempSumForoosh
	delete from #TempCountForoosh



insert into #TempSumForoosh(fldCodeTafzili,fldMablaghForoosh,fldVasete)
			(select  fldCodeTafsili,Sum(fldMablaghKhales) as fldMablaghKhales,fldcodeVasete from tblRizeForoosh where fldDate between @DateAz and @DateTa group by fldCodeTafsili,fldCodeVasete )
			
			--select * from tblRizeForoosh
			--where fldDate between @DateAz and @DateTa 
	insert into #TempCountForoosh(fldShomareFactor,fldCodeTafsili,fldCodeVasete)
	select distinct fldShomareFactor,fldCodeTafsili,fldCodeVasete from tblRizeForoosh where fldDate between @DateAz and @DateTa --and fldCodeTafsili=10294

	--select * from #TempCountForoosh

insert into #TempShow(
fldCodeTafzili,
fldMablaghForoosh,
fldCodeVisitor
)
select fldCodeTafzili,fldMablaghForoosh,fldVasete from #TempSumForoosh

--select * from #TempShow where fldCodeTafzili=10294
update #TempShow set fldTedadForoosh= tbl1.cnt from (select count(fldShomareFactor) as cnt,fldCodeTafsili,fldCodeVasete from #TempCountForoosh group by fldCodeTafsili,fldCodeVasete ) as tbl1 where tbl1.fldCodeTafsili=#TempShow.fldCodeTafzili and tbl1.fldCodeVasete=#TempShow.fldCodeVisitor

update #TempShow set fldcodegroupashkhas= tblTafzili.fldCodeGroup ,fldSharhTafzili=tbltafzili.fldsharhetafzili  from tblTafzili where tbltafzili.fldCodeTafzili=#TempShow.fldCodeTafzili

--insert into #TempShow(
--fldCodeTafzili,
--fldSharhTafzili,
--fldTedadForoosh,
--fldMablaghForoosh,
--fldCodeGroupAshkhas,
--fldNameGroupAshkhas,
--fldCodeVisitor,
--fldNameVisitor
--)
--	(select distinct #TempSumForoosh.fldCodeTafzili as fldCodeTafzili,
--	tblTafzili.fldSharheTafzili as fldSharhTafzili,
--	(select distinct COUNT(fldShomareFactor) from #TempCountForoosh where #TempCountForoosh.fldCodeTafsili=#TempSumForoosh.fldCodeTafzili and tblRizeForoosh.fldCodeVasete=#TempCountForoosh.fldCodeVasete) as fldTedadForoosh,
--	fldMablaghForoosh,
--	tblTafzili.fldCodeGroup as fldCodeGroupAshkhas,
--	'' as fldNameGroupAshkhas
--	,#TempCountForoosh.fldCodeVasete,
--	'' as fldNameVisitor
--	from #TempSumForoosh 
--	inner join tblTafzili on (tblTafzili.fldCodeTafzili=#TempSumForoosh.fldCodeTafzili)
--	inner join #TempCountForoosh on (#TempCountForoosh.fldCodeTafsili=#TempSumForoosh.fldCodeTafzili)
--	inner join tblRizeForoosh on (tblRizeForoosh.fldCodeTafsili=#TempSumForoosh.fldCodeTafzili)
--			where #TempSumForoosh.fldCodeTafzili=10294)



		
update R Set R.fldNameGroupAshkhas=(tblGroupAshkhas.fldGroupName)
								from #TempShow as R 
								inner join tblGroupAshkhas on R.fldCodeGroupAshkhas=tblGroupAshkhas.fldGroupId	

								
update R Set R.fldNameVisitor=(viewLoadVizitor.fldSharheTafzili)
								from #TempShow as R 
								inner join viewLoadVizitor on R.fldCodeVisitor=viewLoadVizitor.fldCodeTafzili					
--delete from #TempShow where fldCodeVisitor NOT Like '10423%'
		if @ListAshkhas<>''
		      begin
		       declare @StrDeleteAshkhas varchar(5000)
		        set  @StrDeleteAshkhas='delete from #TempShow 
		            where '+ @ListAshkhas + ''
					execute(@StrDeleteAshkhas)
		      end

			  	if @ListGroupAshkhas<>''
		      begin
		       declare @StrDeleteGroupAshkhas varchar(5000)
		        set  @StrDeleteGroupAshkhas='delete from #TempShow 
		            where '+ @ListGroupAshkhas + ''
					execute(@StrDeleteGroupAshkhas)
		      end
		
		
		if @ListVisitor<>''
		      begin
		       declare @StrDeleteVisitor varchar(5000)
		        set  @StrDeleteVisitor='delete from #TempShow 
		            where '+ @ListVisitor + ''
					execute(@StrDeleteVisitor)
		      end

	

SELECT  ROW_NUMBER() OVER(ORDER BY fldCodeVisitor) as fldRadif,fldCodeTafzili,fldSharhTafzili,fldTedadForoosh,fldMablaghForoosh,
fldCodeGroupAshkhas,fldNameGroupAshkhas,fldCodeVisitor,fldNameVisitor           
FROM            #TempShow where fldTedadForoosh<>0

END
GO

-- ===============================================
-- SP: [dbo].[z190InsertTarheTakhfifHajmiGroupKala]
-- ===============================================
IF OBJECT_ID(N'dbo.z190InsertTarheTakhfifHajmiGroupKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z190InsertTarheTakhfifHajmiGroupKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z190InsertTarheTakhfifHajmiGroupKala]

@ID bigint,
@fldCodeGroupKala bigint,
@fldRadif bigint,
@fldTedad int,
@fldDarsad decimal(18,2)

as 

begin

	insert into tblTarheTakhfifHajmiGroupKala
		values(@ID,@fldCodeGroupKala,@fldRadif,@fldTedad,@fldDarsad)

end
GO

-- ===============================================
-- SP: [dbo].[z190InsertTarheTakhfifNaghdi]
-- ===============================================
IF OBJECT_ID(N'dbo.z190InsertTarheTakhfifNaghdi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z190InsertTarheTakhfifNaghdi] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z190InsertTarheTakhfifNaghdi]

@ID bigint,
@fldMablagh decimal,
@fldDarsad decimal(18,2),
@countRow bigint

as 

begin

	insert into tblTarheTakhfifNaghdi
		values(@ID,@fldMablagh,@fldDarsad,@countRow)

end
GO

-- ===============================================
-- SP: [dbo].[z191UpdateTblTarheTakhfifHajmiGroupKala]
-- ===============================================
IF OBJECT_ID(N'dbo.z191UpdateTblTarheTakhfifHajmiGroupKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z191UpdateTblTarheTakhfifHajmiGroupKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z191UpdateTblTarheTakhfifHajmiGroupKala]

@fldCodeGroupKala bigint,
@fldRadif bigint,
@fldTedad int,
@fldDarsad int,
@flagOut int output
as

begin
	Update tblTarheTakhfifHajmiGroupKala Set fldTedad =@fldTedad,fldDarsad=@fldDarsad Where fldRadif=@fldRadif and fldCodeGroupKala=@fldCodeGroupKala
	set @flagOut=1
end
GO

-- ===============================================
-- SP: [dbo].[z191UpdateTblTarheTakhfifNaghdi]
-- ===============================================
IF OBJECT_ID(N'dbo.z191UpdateTblTarheTakhfifNaghdi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z191UpdateTblTarheTakhfifNaghdi] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z191UpdateTblTarheTakhfifNaghdi]

@ID int,
@fldMablagh decimal,
@fldDarsad decimal(18,2),
@flagOut int output
as

begin
	Update tblTarheTakhfifNaghdi Set fldMablagh =@fldMablagh,fldDarsad=@fldDarsad Where countRow=@id
	set @flagOut=1
end
GO

-- ===============================================
-- SP: [dbo].[z192DeleteTblTarheTakhfifNaghdi]
-- ===============================================
IF OBJECT_ID(N'dbo.z192DeleteTblTarheTakhfifNaghdi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z192DeleteTblTarheTakhfifNaghdi] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc  [dbo].[z192DeleteTblTarheTakhfifNaghdi]
@ID as int

as
begin
Delete from tblTarheTakhfifNaghdi Where ID=@ID
end
GO

-- ===============================================
-- SP: [dbo].[z192TekrariTedadTakhfifGroupKala]
-- ===============================================
IF OBJECT_ID(N'dbo.z192TekrariTedadTakhfifGroupKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z192TekrariTedadTakhfifGroupKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z192TekrariTedadTakhfifGroupKala]

@TedadTakhfif bigint,
@fldCodeGroupKala bigint,
@fldRadif bigint,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountTakhfif int
	if @IDType=0  --براي مقايسه براي حالت اضافه کردن رکورد
		begin
		 set @RowCountTakhfif=(Select Count(fldTedad) from tblTarheTakhfifHajmiGroupKala  Where fldTedad=@TedadTakhfif and fldCodeGroupKala=@fldCodeGroupKala and  fldRadif<>@fldRadif)
		 set @flagOUt=@RowCountTakhfif
		end
	else
		begin --براي مقايسه با غيرخودش در حالت ويرايش
		   set	@RowCountTakhfif=(Select  Count(fldTedad) from tblTarheTakhfifHajmiGroupKala  Where fldTedad=@TedadTakhfif and fldCodeGroupKala=@fldCodeGroupKala and fldTedad=@TedadTakhfif and  fldRadif<>@fldRadif)
		   set @flagOUt=@RowCountTakhfif
		end
end
GO

-- ===============================================
-- SP: [dbo].[z193ShowtblTarheTakhfifNaghdi]
-- ===============================================
IF OBJECT_ID(N'dbo.z193ShowtblTarheTakhfifNaghdi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z193ShowtblTarheTakhfifNaghdi] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter proc [dbo].[z193ShowtblTarheTakhfifNaghdi]
--@CodeKolHesab nvarChar(8)
as
begin
	select Id,fldMablagh,fldDarsad,countRow from tblTarheTakhfifNaghdi
	ORDER BY fldMablagh 
		--Where fldCodeHesab<>@CodeKolHesab and left(fldCodeHesab,len(@CodeKolHesab))=@CodeKolHesab
		
end
GO

-- ===============================================
-- SP: [dbo].[z194TekrariMablaghTakhfifNaghdi]
-- ===============================================
IF OBJECT_ID(N'dbo.z194TekrariMablaghTakhfifNaghdi', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z194TekrariMablaghTakhfifNaghdi] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z194TekrariMablaghTakhfifNaghdi]

@MablaghTakhfif bigint,
@ID int,
@IDType int,
@flagOUt int output
as
begin
	declare @RowCountTakhfif int
	if @IDType=0  --براي مقايسه براي حالت اضافه کردن رکورد
		begin
		 set @RowCountTakhfif=(Select Count(fldMablagh) from tblTarheTakhfifNaghdi  Where fldMablagh=@MablaghTakhfif)
		 set @flagOUt=@RowCountTakhfif
		end
	else
		begin --براي مقايسه با غيرخودش در حالت ويرايش
		   set	@RowCountTakhfif=(Select  Count(fldMablagh) from tblTarheTakhfifNaghdi  Where fldMablagh=@MablaghTakhfif and countRow<>@ID)
		   set @flagOUt=@RowCountTakhfif
		end
end
GO

-- ===============================================
-- SP: [dbo].[z195MojoodieKalaGheimateMasrafkonande]
-- ===============================================
IF OBJECT_ID(N'dbo.z195MojoodieKalaGheimateMasrafkonande', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z195MojoodieKalaGheimateMasrafkonande] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter proc [dbo].[z195MojoodieKalaGheimateMasrafkonande]

@CodeKala bigint
as 
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	Create Table #tmpMovaghat(
		fldGhymatMasrafkonande nvarchar(20) COLLATE Persian_100_CI_AS,
		TedadeJoz bigint,
		TedadKol nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed1 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldTedadDarKarton bigint
	)

	Create Table #tmpShow(
		fldGhymatMasrafkonande nvarchar(20) COLLATE Persian_100_CI_AS,
		SumTedad bigint,
		TedadKol nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed1 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
		fldTedadDarKarton bigint,
		fldTedadVoroodKartonShow Nvarchar(100) COLLATE Persian_100_CI_AS
	)

	delete #tmpShow
	delete #tmpMovaghat

	insert into #tmpMovaghat
		(fldGhymatMasrafkonande,TedadeJoz)
	Select fldGhymatMasrafkonande,fldTedadJoz  from tblRizeKharid Where fldCodeKala=@CodeKala

		insert into #tmpMovaghat
		(fldGhymatMasrafkonande,TedadeJoz)
	Select convert(dec,fldGhymatMasrafkonande),fldTedadJoz  from tblRizeBargashtAzForoosh Where fldCodeKala=@CodeKala

	insert into #tmpMovaghat
		(fldGhymatMasrafkonande,TedadeJoz)
	Select convert(dec,fldGhymatMasrafkonande),-1*fldTedadJoz  from tblRizeForoosh Where fldCodeKala=@CodeKala

	insert into #tmpMovaghat
		(fldGhymatMasrafkonande,TedadeJoz)
	Select convert(dec,fldGhymatMasrafkonande),-1*fldTedadJozAvalie  from tblRizeTolid Where fldCodeKala=@CodeKala And fldType='avalie'

	insert into #tmpMovaghat
		(fldGhymatMasrafkonande,TedadeJoz)
	Select convert(dec,fldGhymatMasrafkonande),fldTedadJozNahaei  from tblRizetolid Where fldCodeKala=@CodeKala And fldType='mahsool'

	insert into #tmpMovaghat
		(fldGhymatMasrafkonande,TedadeJoz)
	Select convert(dec,fldGhymatMasrafkonande),-1*fldTedadJoz  from tblRizeBargashtAzKharid Where fldCodeKala=@CodeKala

	update #tmpMovaghat set fldGhymatMasrafkonande=0 Where fldGhymatMasrafkonande Is Null
	
	--update #tmpMovaghat set fldGhymatMasrafkonande= substring(convert(nvarchar(10),DateEngheza),0,5) +'/' +substring(convert(nvarchar(10),DateEngheza),5,2) + '/' + substring(convert(nvarchar(10),DateEngheza),7,2) where DateEngheza<>'0'
	
	update #tmpMovaghat set fldNameVahed1=tbl1.fldNameVahed from
		(Select fldNameVahed,fldCodeKala from tblVahed,tblKala Where tblVahed.ID=tblKala.fldCodeVahed1 and fldCodeKala=@CodeKala) as tbl1 where 1=1

	
	update #tmpMovaghat set fldNameVahed2=tbl1.fldNameVahed from
		(Select fldNameVahed,fldCodeKala from tblVahed,tblKala Where tblVahed.ID=tblKala.fldCodeVahed2 and fldCodeKala=@CodeKala) as tbl1 where 1=1



	Insert into #tmpShow (fldGhymatMasrafkonande,SumTedad,fldNameVahed1,fldNameVahed2,fldTedadDarKarton)
		Select   convert(dec,fldGhymatMasrafkonande) ,Sum(TedadeJoz) As SumTedad,fldNameVahed1,fldNameVahed2,fldTedadDarKarton  from #tmpMovaghat group by  convert(dec,fldGhymatMasrafkonande),fldNameVahed1,fldNameVahed2,fldTedadDarKarton

	declare @TedadDarKarton bigint
	set @TedadDarKarton=(select fldTedadJoz from tblKala where fldCodeKala=@CodeKala)

	
	if @TedadDarKarton>0 
		update #tmpShow Set TedadKol=Convert(varchar,floor(SumTedad / @TedadDarKarton)) + ' ' + fldNameVahed2 +  Convert(varchar, { fn MOD(SumTedad, @TedadDarKarton) } ) + ' ' + fldNameVahed1			
	else
		update #tmpShow Set TedadKol=''

	Select fldGhymatMasrafkonande ,SumTedad ,TedadKol,fldNameVahed1,fldNameVahed2 from #tmpShow
	
end
GO

-- ===============================================
-- SP: [dbo].[z196ShowList_ReportEnteghalBainAnbar]
-- ===============================================
IF OBJECT_ID(N'dbo.z196ShowList_ReportEnteghalBainAnbar', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z196ShowList_ReportEnteghalBainAnbar] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z196ShowList_ReportEnteghalBainAnbar]
	--@ListRanande varchar(5000)=null,
	@ListCodeShakhsTahvilDahande varchar(5000)=null,
	@ListCodeShakhsTahvilGirande varchar(5000)=null,
    @ListCodeAnbarTahvilDahande varchar(5000)=null,
	@ListCodeAnbarTahvilGirande varchar(5000)=null,
	@ListKarbaran varchar(5000)=null
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
 



create table #TempShow(
fldShomareEnteghal bigint,
fldCodeKala bigint,
fldSharheKala NVarchar(100) COLLATE Persian_100_CI_AS,
fldTedadeVorood bigint,
fldTedadeKhorooj bigint,

fldCodeShakhsTahvilDahande bigint,
fldNameShakhsTahvilDahande NVarchar(100) COLLATE Persian_100_CI_AS,

fldCodeShakhsTahvilGirande bigint,
fldNameShakhsTahvilGirande NVarchar(100) COLLATE Persian_100_CI_AS,

fldCodeAnbarTahvilDahande bigint,
fldNameAnbarTahvilDahande NVarchar(100) COLLATE Persian_100_CI_AS,

fldCodeAnbarTahvilGirande bigint,
fldNameAnbarTahvilGirande NVarchar(100) COLLATE Persian_100_CI_AS,

fldDate NVarchar(100) COLLATE Persian_100_CI_AS,
fldCodeKarbar bigint,
fldNameKarbar NVarchar(100) COLLATE Persian_100_CI_AS,
fldSharh NVarchar(100) COLLATE Persian_100_CI_AS
)

delete #TempShow



insert into #TempShow(fldShomareEnteghal,fldCodeKala,fldTedadeVorood,fldTedadeKhorooj
					  ,fldCodeShakhsTahvilDahande,fldNameShakhsTahvilDahande
					  ,fldCodeShakhsTahvilGirande,fldNameShakhsTahvilGirande
					  ,fldCodeAnbarTahvilDahande,fldNameAnbarTahvilDahande
					  ,fldCodeAnbarTahvilGirande,fldNameAnbarTahvilGirande
					  ,fldDate
					  ,fldCodeKarbar
					  ,fldNameKarbar
					  ,fldSharh)
select distinct tblRizeForoosh.fldShomareEnteghal,tblRizeForoosh.fldCodeKala as fldCodeKala,tblRizeKharid.fldTedadJoz as fldTedadeVorood,  tblRizeForoosh.fldTedadJoz as fldTedadeKhorooj
			,tblRizeForoosh.fldCodeTafsili as fldCodeShakhsTahvilDahande
			,'' as fldNameShakhsTahvilDahande
			,tblRizeKharid.fldCodeTafsili as fldCodeShakhsTahvilGirande
			,'' as fldNameShakhsTahvilGirande
			,tblRizeForoosh.fldCodeAnbar as fldCodeAnbarTahvilDahande
			,'' as fldNameAnbarTahvilDahande
			,tblRizeKharid.fldCodeAnbar as fldCodeAnbarTahvilGirande
			,'' as fldNameAnbarTahvilGirande
			,tblRizeForoosh.fldDate
			,tblRizeForoosh.fldCodeUser,'' as fldNameKarbar
			,tblRizeForoosh.fldSharhKala  from tblRizeForoosh inner join
			tblRizeKharid on tblRizeForoosh.fldShomareEnteghal=tblRizeKharid.fldShomareEnteghal and tblRizeForoosh.fldCodeKala=tblRizeKharid.fldCodeKala
where tblRizeForoosh.fldType='enteghal'

--select fldShomareEnteghal,fldCodeTafsili,fldDate from tblRizeKharid where fldType='enteghal'

--select * from #TempShow

	update R Set R.fldNameShakhsTahvilDahande=(tblTafzili.fldSharheTafzili)
								from #TempShow as R 
								inner join tblTafzili on R.fldCodeShakhsTahvilDahande=tblTafzili.fldCodeTafzili

	update R Set R.fldNameShakhsTahvilGirande=(tblTafzili.fldSharheTafzili)
								from #TempShow as R 
								inner join tblTafzili on R.fldCodeShakhsTahvilGirande=tblTafzili.fldCodeTafzili
								
	update R Set R.fldNameAnbarTahvilDahande=(tblAnbar.fldNameAnbar)
								from #TempShow as R 
								inner join tblAnbar on R.fldCodeAnbarTahvilDahande=tblAnbar.fldCode

	update R Set R.fldNameAnbarTahvilGirande=(tblAnbar.fldNameAnbar)
								from #TempShow as R 
								inner join tblAnbar on R.fldCodeAnbarTahvilGirande=tblAnbar.fldCode
		
		update #TempShow set fldSharheKala=tblKala.fldNameKala from tblKala where #TempShow.fldCodeKala=tblKala.fldCodeKala


		if @ListKarbaran <>''
   begin
		 declare @StrDeleteKarbaran varchar(5000)
	     set  @StrDeleteKarbaran='delete from #TempShow 
		 where '+ @ListKarbaran + ''
		execute(@StrDeleteKarbaran)
	end

	if @ListCodeAnbarTahvilDahande <>''
   begin
			delete #TempShow where  fldCodeAnbarTahvilDahande<>@ListCodeAnbarTahvilDahande and fldCodeAnbarTahvilGirande<>@ListCodeAnbarTahvilDahande
		-- declare @StrDeleteAnbarTahvilDahande varchar(5000)
	 --    set  @StrDeleteAnbarTahvilDahande='delete from #TempShow 
		-- where '+ @ListCodeAnbarTahvilDahande + ''
		--execute(@StrDeleteAnbarTahvilDahande)
	end
	--if @ListCodeAnbarTahvilGirande <>''
 --  begin
	--	 declare @StrDeleteAnbarTahvilGirande varchar(5000)
	--     set  @StrDeleteAnbarTahvilGirande='delete from #TempShow 
	--	 where '+ @ListCodeAnbarTahvilGirande + ''
	--	execute(@StrDeleteAnbarTahvilGirande)
	--end
	if @ListCodeShakhsTahvilDahande <>''
   begin
		 declare @StrDeleteShakhsTahvilDahande varchar(5000)
	     set  @StrDeleteShakhsTahvilDahande='delete from #TempShow 
		 where '+ @ListCodeShakhsTahvilDahande + ''
		execute(@StrDeleteShakhsTahvilDahande)
	end													

	 	if @ListCodeShakhsTahvilGirande <>''
   begin
		 declare @StrDeleteShakhsTahvilGirande varchar(5000)
	     set  @StrDeleteShakhsTahvilGirande='delete from #TempShow 
		 where '+ @ListCodeShakhsTahvilGirande + ''
		execute(@StrDeleteShakhsTahvilGirande)
	end

update #TempShow set fldTedadeKhorooj=0  where fldCodeAnbarTahvilDahande=@ListCodeAnbarTahvilDahande
update #TempShow set fldTedadeVorood=0  where fldCodeAnbarTahvilGirande=@ListCodeAnbarTahvilDahande

select ROW_NUMBER() OVER(ORDER BY fldShomareEnteghal) as fldRadif,
fldShomareEnteghal
,fldCodeKala
,fldSharheKala
,fldNameAnbarTahvilDahande
,fldNameShakhsTahvilDahande
,fldNameAnbarTahvilGirande
,fldNameShakhsTahvilGirande,
SUBSTRING(CONVERT(nvarchar,fldDate), 1, 4) + '/' +
SUBSTRING(CONVERT(nvarchar, fldDate), 5, 2) + '/' +
SUBSTRING(CONVERT(nvarchar, fldDate), 7, 2) AS fldDate,fldNameKarbar,fldSharh
,fldCodeShakhsTahvilDahande
,fldCodeKarbar
,fldCodeShakhsTahvilGirande
,fldCodeAnbarTahvilDahande
,fldCodeAnbarTahvilGirande
,fldTedadeVorood
,fldTedadeKhorooj from #TempShow


END
GO

-- ===============================================
-- SP: [dbo].[z197ShowList_ReportMarKazHazineKol]
-- ===============================================
IF OBJECT_ID(N'dbo.z197ShowList_ReportMarKazHazineKol', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z197ShowList_ReportMarKazHazineKol] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z197ShowList_ReportMarKazHazineKol]
	@Code bigint,
	@DateAz bigint,
	@DateTa bigint
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
  



 SELECT        ROW_NUMBER() OVER(ORDER BY tbl1.fldCodeKol) as fldRadif,tbl1.fldCodeKol, tblKolMoin.fldSharheHesab, tbl1.sumBed, tbl1.sumBes
                            FROM            tblKolMoin INNER JOIN
                             (SELECT        fldCodeKol, SUM(fldBedehkar) AS sumBed, SUM(fldBestankar) AS sumBes
                                FROM            tblSodooreSanad
                                WHERE        (fldCodeMarkaz1 =@Code And fldDate between @DateAz And @DateTa)
                                GROUP BY fldCodeKol) AS tbl1 ON tblKolMoin.fldCodeHesab = tbl1.fldCodeKol


 
END
GO

-- ===============================================
-- SP: [dbo].[z198ShowList_ReportMarKazHazineMoin]
-- ===============================================
IF OBJECT_ID(N'dbo.z198ShowList_ReportMarKazHazineMoin', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z198ShowList_ReportMarKazHazineMoin] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z198ShowList_ReportMarKazHazineMoin]
	@Code bigint,
	@DateAz bigint,
	@DateTa bigint
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
  



SELECT       ROW_NUMBER() OVER(ORDER BY tbl1.fldMoinKamel) as fldRadif, tbl1.fldMoinKamel, tblKolMoin.fldSharheHesab, tbl1.sumBed, tbl1.sumBes
                                FROM            tblKolMoin INNER JOIN
                             (SELECT        fldMoinKamel, SUM(fldBedehkar) AS sumBed, SUM(fldBestankar) AS sumBes
                                FROM            tblSodooreSanad
                                WHERE        (fldCodeMarkaz1 = @Code And fldDate between @DateAz And @DateTa)
                                GROUP BY fldMoinKamel) AS tbl1 ON tblKolMoin.fldCodeHesab = tbl1.fldMoinKamel


 
END
GO

-- ===============================================
-- SP: [dbo].[z199ShowList_ReportMarKazHazineTafzili]
-- ===============================================
IF OBJECT_ID(N'dbo.z199ShowList_ReportMarKazHazineTafzili', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z199ShowList_ReportMarKazHazineTafzili] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z199ShowList_ReportMarKazHazineTafzili]
	@Code bigint,
	@DateAz bigint,
	@DateTa bigint
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
  



SELECT        ROW_NUMBER() OVER(ORDER BY fldCodeTafzili) as fldRadif,fldCodeTafzili, fldSharheTafzili, fldMoinKamel,fldSharheHesab, sumBed, sumBes FROM   tblKolMoin,
                        (SELECT        tblTafzili.fldCodeTafzili, tblTafzili.fldSharheTafzili, tbl1.fldMoinKamel, tbl1.sumBed, tbl1.sumBes
                              FROM            tblTafzili INNER JOIN
                                (SELECT        fldCodeTafzili, fldMoinKamel, SUM(fldBedehkar) AS sumBed, SUM(fldBestankar) AS sumBes
                                 FROM            tblSodooreSanad
                                WHERE        (fldCodeMarkaz1 = @Code  And fldDate between @DateAz And @DateTa)
                                GROUP BY fldCodeTafzili, fldMoinKamel) AS tbl1 ON tblTafzili.fldCodeTafzili = tbl1.fldCodeTafzili) AS tbl2
                        where fldMoinKamel=fldCodeHesab



 
END
GO

-- ===============================================
-- SP: [dbo].[z200ShowList_ReportMarKazHazineAsnad]
-- ===============================================
IF OBJECT_ID(N'dbo.z200ShowList_ReportMarKazHazineAsnad', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[z200ShowList_ReportMarKazHazineAsnad] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[z200ShowList_ReportMarKazHazineAsnad]
	@Code bigint,
	@DateAz bigint,
	@DateTa bigint
as
   
	
IF 1=0 BEGIN
 SET FMTONLY OFF
END
begin
	
	SET NOCOUNT ON;
  



 SELECT        ROW_NUMBER() OVER(ORDER BY fldSanad) as fldRadif,fldSanad, SUBSTRING(CONVERT(nvarchar(10), fldDate), 0, 5) + '/' + SUBSTRING(CONVERT(nvarchar(10), fldDate), 5, 2) + '/' + SUBSTRING(CONVERT(nvarchar(10), 
                         fldDate), 7, 2) AS fldDate, fldCodeTafzili, fldMoinKamel, fldBedehkar, fldBestankar
                        FROM            tblSodooreSanad
                        WHERE        (fldCodeMarkaz1 = @Code  And fldDate between @DateAz And @DateTa)
                        ORDER BY fldDate



 
END
GO

-- ===============================================
-- SP: [dbo].[ZSP_Apply_Raffles]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_Apply_Raffles', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_Apply_Raffles] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ZSP_Apply_Raffles]
	-- Add the parameters for the stored procedure here
	@TotalCost bigint
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 top 1 fldcodekala,fldcount,fldprice from tbleshantionmablagy 
  where fldprice <= @TotalCost 
  order by fldprice desc
END
GO

-- ===============================================
-- SP: [dbo].[ZSP_GetAccessableAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_GetAccessableAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_GetAccessableAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_GetAccessableAshkhas] 
	-- Add the parameters for the stored procedure here
	@usercode bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

  Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPASHKHAS')
  if @value = 'True'
  Begin -- Limitation Active

    declare @groups table(fldCode bigint)
	 insert into @groups(fldCode)
	 exec ZSP_GetGroupAshkhasAccess @usercode


 select fldCodeTafzili,fldCodeGroup,fldSharheTafzili from tblTafzili as t
 inner join @groups as g on convert(nvarchar(100),t.fldCodeGroup) like convert(nvarchar(100),g.fldCode) + '%'
 group by fldCodeTafzili,fldCodeGroup,fldSharheTafzili
 order by CONVERT(varchar,fldCodeTafzili )


  End
  else
  Begin -- Limitation DeActive
	select fldCodeTafzili,fldCodeGroup,fldSharheTafzili from tblTafzili
	order by CONVERT(varchar,fldCodeTafzili )
  End
	 
END
GO

-- ===============================================
-- SP: [dbo].[ZSP_GetAccessableGroupAshkhas]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_GetAccessableGroupAshkhas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_GetAccessableGroupAshkhas] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_GetAccessableGroupAshkhas] 
	-- Add the parameters for the stored procedure here
	@usercode bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

  Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPASHKHAS')
  if @value = 'True'
  Begin -- Limitation Active

  declare @tbl table(fldCode bigint) -- in fact -> fldCodeGroupKala 
 insert @tbl(fldCode)
 exec ZSP_GetGroupAshkhasAccess @usercode
 
 select fldGroupId,fldGroupName from tblGroupAshkhas 
 where  fldGroupId in(select fldCode from @tbl)
 order by CONVERT(varchar,fldGroupId )

  End
  else
  Begin -- Limitation DeActive
	select fldGroupId,fldGroupName from tblGroupAshkhas
	order by CONVERT(varchar,fldGroupId )
  End
	 
END
GO

-- ===============================================
-- SP: [dbo].[ZSP_GetAccessableGroupKala]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_GetAccessableGroupKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_GetAccessableGroupKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_GetAccessableGroupKala] 
	-- Add the parameters for the stored procedure here
	@usercode bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

  Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA')
  if @value = 'True'
  Begin -- Limitation Active

  declare @tbl table(fldkalacode bigint) -- in fact -> fldCodeGroupKala 
 insert @tbl(fldkalacode)
 exec ZSP_GetKalaAccesses @usercode
 
 select fldGroupId,fldGroupName from viewShowListSmallGroupKala where  fldGroupId in(select fldkalacode from @tbl)

  End
  else
  Begin -- Limitation DeActive
	select fldGroupId,fldGroupName from viewShowListSmallGroupKala
  End


 
	 
END
GO

-- ===============================================
-- SP: [dbo].[ZSP_GetAccessableGroupKalaCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_GetAccessableGroupKalaCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_GetAccessableGroupKalaCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_GetAccessableGroupKalaCode] 
	-- Add the parameters for the stored procedure here
	@usercode bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

  Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA')
  if @value = 'True'
  Begin -- Limitation Active


 declare @tbl table(fldkalacode bigint) -- in fact -> fldCodeGroupKala 
 insert @tbl(fldkalacode)
 --exec ZSP_GetKalaAccesses @usercode--to ignore nested insert
 select fldKalaCode from tblGroupKalaAccess where fldUserCode = @usercode 


  select fldGroupId as code from viewShowListSmallGroupKala 
 where  fldGroupId in(select fldkalacode from @tbl)
 order by CONVERT(varchar,fldGroupId )

  End
  else
  Begin -- Limitation DeActive
	select fldGroupId as code from viewShowListSmallGroupKala
	order by CONVERT(varchar,fldGroupId )
  End

END
GO

-- ===============================================
-- SP: [dbo].[ZSP_GetAccessableKala]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_GetAccessableKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_GetAccessableKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_GetAccessableKala] 
	-- Add the parameters for the stored procedure here
	@userCode bigint ,
	@int1 bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	declare @kalas table(
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldFeeForoosh money,
fldmodat int,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
SumMande Nvarchar(100) COLLATE Persian_100_CI_AS,
fldTedadDarKartonShow Nvarchar(100) COLLATE Persian_100_CI_AS
)
 insert into @kalas(fldCodeKala,fldNameKala,fldNameVahed,fldNameVahed2,SumMande,fldFeeForoosh,fldmodat,fldCodeGroup,fldTedadDarKartonShow)
 exec ShowListMojoodieAnbarForForoosh 1
 

  Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA')
  if @value = 'True'
  Begin -- Limitation Active

	  declare @groups table(fldKalaCode bigint)
	 insert into @groups(fldKalaCode)
	 exec ZSP_GetKalaAccesses 1000
	 
	 --select * from @groups -- 100,101
	 
	 select fldCodeKala,fldCodeGroup,fldNameKala from @kalas
	 as k inner join @groups as g on convert(nvarchar(100),k.fldCodeGroup) like convert(nvarchar(100),g.fldKalaCode) + '%'
	 group by fldCodeKala ,fldCodeGroup,fldNameKala 
	  order by fldCodeKala 

  End -- end of limitation
  else
  Begin
	select fldCodeKala,fldCodeGroup,fldNameKala from @kalas
  End
 
End
GO

-- ===============================================
-- SP: [dbo].[ZSP_GetFUllMemberAccessableKala]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_GetFUllMemberAccessableKala', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_GetFUllMemberAccessableKala] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_GetFUllMemberAccessableKala] 
	-- Add the parameters for the stored procedure here
	@userCode bigint ,
	@int1 bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	declare @kalas table(
fldCodeGroup bigint,
fldCodeKala bigint,
fldNameKala nvarchar(100) COLLATE Persian_100_CI_AS,
fldFeeForoosh money,
fldNameVahed NVarchar(100) COLLATE Persian_100_CI_AS,
fldNameVahed2 Nvarchar(100) COLLATE Persian_100_CI_AS,
SumMande Nvarchar(100) COLLATE Persian_100_CI_AS,
fldTedadDarKartonShow Nvarchar(100) COLLATE Persian_100_CI_AS,
fldModat int
)
 insert into @kalas(fldCodeKala,fldNameKala,fldNameVahed,fldNameVahed2,SumMande,fldFeeForoosh,fldModat,fldCodeGroup,fldTedadDarKartonShow)
 exec ShowListMojoodieAnbarForForoosh @int1
 

  Declare @value nvarchar(100)
  set @value =( select fldMeghdar from tblTanzimateKol  where fldType = 'ACCESSGROUPKALA')
  if @value = 'True'
  Begin -- Limitation Active

	  declare @groups table(fldKalaCode bigint)
	 insert into @groups(fldKalaCode)
	 exec ZSP_GetKalaAccesses @usercode
	 
	 --select * from @groups -- 100,101
	 
	 select fldCodeKala ,fldNameKala,fldNameVahed,fldNameVahed2,SumMande,fldFeeForoosh,fldModat,fldCodeGroup,fldTedadDarKartonShow
	 from @kalas
	 as k inner join @groups as g on convert(nvarchar(100),k.fldCodeGroup) like convert(nvarchar(100),g.fldKalaCode) + '%'
	 group by fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumMande,fldFeeForoosh,fldModat,fldCodeGroup,fldTedadDarKartonShow 
	 order by fldCodeKala 

  End -- end of limitation
  else
  Begin
	select fldCodeKala ,fldNameKala,fldNameVahed ,fldNameVahed2,SumMande,fldFeeForoosh,fldModat,fldCodeGroup,fldTedadDarKartonShow
	from @kalas

  End
 
End
GO

-- ===============================================
-- SP: [dbo].[ZSP_GetGroupAshkhasAccess]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_GetGroupAshkhasAccess', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_GetGroupAshkhasAccess] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_GetGroupAshkhasAccess]
	-- Add the parameters for the stored procedure here
	@userCode bigint
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 fldGroupCode from tblGroupAshkhasAccess where fldUserCode = @userCode 
END
GO

-- ===============================================
-- SP: [dbo].[ZSP_GetKalaAccesses]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_GetKalaAccesses', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_GetKalaAccesses] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_GetKalaAccesses]
	-- Add the parameters for the stored procedure here
	@userCode bigint
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 fldKalaCode from tblGroupKalaAccess where fldUserCode = @userCode 
END
GO

-- ===============================================
-- SP: [dbo].[ZSP_GrantGroupAshkhasAccess]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_GrantGroupAshkhasAccess', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_GrantGroupAshkhasAccess] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_GrantGroupAshkhasAccess]
	-- Add the parameters for the stored procedure here
	@userCode Bigint,
	@GroupCodes [dbo].[ZT_CodeNumbers] 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;
	-- Set Group kala access
	Begin Transaction
	Begin Try
		 delete from tblGroupAshkhasAccess where fldUserCode = @userCode

		insert into tblGroupAshkhasAccess(fldUserCode,fldGroupCode)
			select @userCode,CodeNumber from @GroupCodes

		Commit Transaction
	End Try
	Begin Catch
		Rollback Transaction
	End Catch
    -- Insert statements for procedure here
	--select @userCode,[CodeNumber] from @GroupCodes
END
GO

-- ===============================================
-- SP: [dbo].[ZSP_GrantKalaAccess]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_GrantKalaAccess', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_GrantKalaAccess] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_GrantKalaAccess]
	-- Add the parameters for the stored procedure here
	@userCode bigint
	,@kalaCodes varchar(max)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    
	Begin Transaction GKA
	 Begin Try

	  declare @tmp table(number bigint)
	  insert into @tmp(number)
		select number from dbo.ZF_SplitString(@kalaCodes,',')

	  delete from tblGroupKalaAccess where fldUserCode = @userCode

	  insert into tblGroupKalaAccess(fldUserCode,fldKalaCode)
			select @userCode,number from @tmp
	  
	  Commit Transaction GKA
	 End Try
	 Begin Catch
		Rollback Transaction GKA
	 End Catch




END
GO

-- ===============================================
-- SP: [dbo].[ZSP_KallaAccess]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_KallaAccess', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_KallaAccess] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_KallaAccess]
	-- Add the parameters for the stored procedure here
	@userCode Bigint,
	@kalaCodes [dbo].[ZT_CodeNumbers] 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
	Begin Try
		 delete from tblGroupKalaAccess where fldUserCode = @userCode

		insert into tblGroupKalaAccess(fldUserCode,fldKalaCode)
			select @userCode,CodeNumber from @kalaCodes

		Commit Transaction
	End Try
	Begin Catch
		Rollback Transaction
	End Catch
    -- Insert statements for procedure here
	select @userCode,[CodeNumber] from @kalaCodes
END
GO

-- ===============================================
-- SP: [dbo].[ZSP_LastEnteghalCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_LastEnteghalCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_LastEnteghalCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ZSP_LastEnteghalCode]
	-- Add the parameters for the stored procedure here
	@Code bigint out
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	declare @tmp bigint = (select max(fldShomareEnteghal) from tblCheckeDaryafti)
	if @tmp is Null or @tmp =  0 
	begin
	 set @Code = 1
	end
	else
	begin
	 set @Code = @tmp + 1
	end
END
GO

-- ===============================================
-- SP: [dbo].[ZSP_LastOdatCode]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_LastOdatCode', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_LastOdatCode] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ZSP_LastOdatCode]
	-- Add the parameters for the stored procedure here
	@Code bigint out
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	declare @tmp bigint = (select max(fldShomareOdat) from tblCheckeDaryafti)
	if @tmp is Null or @tmp =  0 
	begin
	 set @Code = 1
	end
	else
	begin
	 set @Code = @tmp + 1
	end
END
GO

-- ===============================================
-- SP: [dbo].[ZSP_viewFilter_Tbl_Tafsili_in_Form_Enteghal_Kalas]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_viewFilter_Tbl_Tafsili_in_Form_Enteghal_Kalas', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_viewFilter_Tbl_Tafsili_in_Form_Enteghal_Kalas] AS BEGIN SET NOCOUNT ON; END')
END
GO

Alter PROCEDURE [dbo].[ZSP_viewFilter_Tbl_Tafsili_in_Form_Enteghal_Kalas]
	-- Add the parameters for the stored procedure here
	@userCode bigint
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.

	SET NOCOUNT ON;

	declare @accessCodes table(code bigint)
	declare @accessPersonel table(code bigint)
	insert into @accessCodes select * from ZF_GetAccessableAshkhasCode(@userCode) 
	insert into @accessCodes select  fldCodeTafzili from tblTafzili where fldCodeNoe='0' --برای زمانیه که به گروه لیست اشخاص دسترسی نداره و میخام پرسنل در این گروه رو نشون بده

	declare @dastrasiPersonel nvarchar(20)
	execute ShowTanzimatNew 'DastrasiPersonel',@dastrasiPersonel  output
	--select @dastrasiPersonel
	if  @dastrasiPersonel='1'
		insert into @accessPersonel
			select fldCodeTafzili from tblTafzili where fldCodeNoe='0' and fldCodeTafzili not in 
			(select fldcodetafzili from tblDastrasiPersonel where fldcodeUser=@userCode) 

	select  fldCodeTafzili, fldSharheTafzili,fldAddress,fldGroupName from 
		(SELECT  fldCodeTafzili, fldSharheTafzili,fldAddress,fldGroupName
		FROM   viewFilter_Tbl_Tafsili_in_Form_Enteghal_Kala
		where fldCodeTafzili in (select code from @accessCodes)) as tbl1
	where fldCodeTafzili not in (select code from @accessPersonel)


END
GO

-- ===============================================
-- SP: [dbo].[ZSP_VisitorSalaryAndPorsant]
-- ===============================================
IF OBJECT_ID(N'dbo.ZSP_VisitorSalaryAndPorsant', N'P') IS NULL
BEGIN
    EXEC('CREATE PROCEDURE [dbo].[ZSP_VisitorSalaryAndPorsant] AS BEGIN SET NOCOUNT ON; END')
END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[ZSP_VisitorSalaryAndPorsant] 
	-- Add the parameters for the stored procedure here
	@tafzili nvarchar(max),
	@moien nvarchar(max),
	@fromDate bigint,
	@toDate bigint
AS
BEGIN
	SELECT fldCodeTafzili,fldMoinKamel,sum(fldBedehkar) as Bedehkar,sum(fldBestankar) as Bestankar	
	from tblSodooreSanad 
	where 
	(fldDate between @fromDate and @toDate) 
	and
	fldMoinKamel in (select number from ZF_SplitString(@moien,','))  --(61201,31303,31303,31399,61111,31399)
	and fldCodeTafzili in (select number from ZF_SplitString(@tafzili,','))

	group by fldMoinKamel,fldCodeTafzili
END
GO

-- ===============================================
-- DATA RESET & INSERT (IDENTITY SAFE)
-- ===============================================

-- TABLE: tblListeDastrasi
DELETE FROM [dbo].[tblListeDastrasi]
GO

SET IDENTITY_INSERT [dbo].[tblListeDastrasi] ON
GO

INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (1,100,'فروش',1,1,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (2,101,'امکان حذف فاکتور فروش',1,2,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (3,102,'امکان ويرايش فاکتور فروش',1,3,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (4,103,'امکان ثبت فاکتور فروش اعتباري',1,4,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (5,104,'امکان مشاهده آرشيو فاکتور فروش',1,5,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (6,105,'امکان تغيير في فروش',1,6,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (7,106,'امکان مشاهده انبار جاري در فاکتور فروش',1,7,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (8,107,'امکان مشاهده انبار کل در فاکتور فروش',1,8,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (9,108,'امکان ويرايش فاکتور توسط کاربر ديگر',1,9,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10012,109,'امکان مشاهده آخرين في خريد در فرم فروش',1,10,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30085,110,'ثبت فاکتور به تاريخ غيرجاري',1,11,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30086,111,'محسابه سود فاکتور',1,12,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30087,112,'سود کالا در فاکتور ',1,13,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30089,113,'امکان حذف فاکتور به تاريخ غيرجاري',1,14,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30090,114,'امکان ويرايش فاکتور به تاريخ غيرجاري',1,15,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30092,115,'ثبت فاکتور فقط به تاريخ جاري',1,16,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30156,116,'اصلاح کلي فاکتورها',1,17,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30157,117,'مرتب سازي فاکتورها',1,18,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30162,118,'چاپ فاکتور قبل از ثبت نهايي فاکتور',1,19,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30163,119,'پيش نمايش قبل از ثبت نهايي فاکتور',1,20,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30171,120,'مجوز حذف فاکتور مربوط به کاربر ديگر',1,21,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30172,121,'مجوز ويرايش فاکتور مربوط به کاربر ديگر',1,22,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30185,122,'مجوز ثبت تخفيف براي هر قلم کالا',1,23,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30202,123,'گزارش ليستي فروش',1,24,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30209,124,'قابل تغيير بودن شماره فاکتور در حالت بارکدخوان',1,25,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30214,125,'مجوز فروش به شخصي که بدهي قبلي دارد',1,26,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (12,200,'خريد',2,1,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10,201,'امکان حذف فاکتور خريد',2,2,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (11,202,'امکان ويرايش فاکتور خريد',2,3,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10015,203,'امکان مشاهده آرشيو فاکتور خريد',2,4,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10016,204,'امکان مشاهده انبار جاري در فاکتور خريد',2,5,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10017,205,'امکان مشاهده انبار کل در فاکتور خريد',2,6,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10018,206,'امکان ثبت فاکتور خريد اعتباري',2,7,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10019,207,'امکان مشاهده آخرين في خريد در فرم خريد',2,8,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30097,208,'امکان حذف فاکتور خريد به تاريخ غيرجاري',2,9,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30098,209,'امکان ويرايش فاکتور خريد به تاريخ غيرجاري',2,10,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30205,210,'گزارش ليستي خريد',2,11,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40226,211,'گزارش سررسيد خريد',2,12,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10020,300,'برگشت از فروش',3,1,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10021,301,'امکان حذف برگشت از فروش',3,2,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10022,302,'امکان ويرايش برگشت از فروش',3,3,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10023,303,'امکان ثبت برگشت از فروش اعتباري',3,4,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10024,304,'امکان مشاهده آرشيو برگشت از فروش',3,5,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10025,305,'امکان تغيير في فروش',3,6,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10026,306,'امکان مشاهده انبار جاري در برگشت از فروش',3,7,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (10027,307,'امکان مشاهده انبار کل در برگشت از فروش',3,8,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30100,308,'امکان حذف برگشت از فروش به تاريخ غيرجاري',3,9,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30101,309,'امکان ويرايش برگشت از فروش به تاريخ غيرجاري',3,10,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30203,310,'گزارش ليستي برگشت از فروش',3,11,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (20012,400,'برگشت از خريد',4,1,'برگشت از خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (20013,401,'امکان حذف برگشت از خريد',4,2,'برگشت از خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (20014,402,'امکان ويرايش برگشت از خريد',4,3,'برگشت از خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (20015,403,'امکان مشاهده آرشيو برگشت از خريد',4,4,'برگشت از خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (20016,404,'امکان مشاهده انبار جاري در برگشت از خريد',4,5,'برگشت از خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (20017,405,'امکان مشاهده انبار کل در برگشت از خريد',4,6,'برگشت از خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (20018,406,'امکان ثبت برگشت از خريد اعتباري',4,7,'برگشت از خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (20019,407,'امکان مشاهده آخرين في خريد در برگشت از خريد',4,8,'برگشت از خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30206,408,'گزارش ليستي برگشت از خريد',4,9,'برگشت از خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30013,500,'پيش فاکتور',5,1,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30093,501,'امکان حذف پيش فاکتور',5,2,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30095,502,'امکان ويرايش پيش فاکتور',5,3,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30094,503,'امکان ويرايش پيش فاکتور به تاريخ غيرجاري',5,4,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30096,504,'امکان حذف پيش فاکتور به تاريخ غيرجاري',5,5,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30158,505,'تبديل پيش فاکتورهايي که موجودي منفي دارند',5,6,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30160,506,'اجازه تبديل مجدد پيش فاکتور',5,7,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30161,507,'اجازه اصلاح پيش فاکتوري که به فاکتور تبديل گرديده است',5,8,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30164,508,'چاپ پيش فاکتور قبل از ثبت نهايي',5,9,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30165,509,'پيش نمايش قبل از ثبت نهايي پيش فاکتور',5,10,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30173,510,'مجوز حذف پيش فاکتور مربوط به کاربر ديگر',5,11,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30174,511,'مجوز ويرايش پيش فاکتور مربوط به کاربر ديگر',5,12,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30182,512,'نمايش موجودي انبار جاري',5,13,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30183,513,'نمايش موجودي همه انبارها',5,14,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30186,514,'مجوز ثبت تخفيف براي هر قلم کالا',5,15,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40230,515,'گزارش پيش فاکتور',5,16,'پيش فاکتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30014,550,'سفارشات ويزيتورها',6,1,'سفارشات ويزيتورها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40229,551,'ليست سفارشات ويزيتورها',6,2,'سفارشات ويزيتورها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30015,600,'مسير حرکت ويزيتورها',7,1,'مسير حرکت ويزيتورها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40231,601,'موقعيت مشتريان روي نقشه',7,1,'مسير حرکت ويزيتورها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30016,610,'انتقال کالا بين انبار',8,1,'انتقال کالا بين انبار')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30017,640,'حواله گروهي',9,1,'حواله گروهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30106,641,'ثبت حواله گروهي',9,2,'حواله گروهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30107,642,'حذف حواله گروهي',9,3,'حواله گروهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30108,643,'ثبت حواله گروهي به تاريخ غيرجاري',9,4,'حواله گروهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30122,644,'امکان حذف حواله گروهي به تاريخ غيرجاري',9,5,'حواله گروهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30207,645,'گزارش ليست انتقال کالا بين انبار',9,6,'حواله گروهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30213,646,'مجوز ثبت مجدد فاکتوري که قبلا حواله شده است',9,7,'حواله گروهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40240,647,'وضعيت تسويه حواله',9,8,'حواله گروهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40241,648,'گزارش عملکرد و پورسانت راننده',9,9,'حواله گروهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30018,650,'دريافت مطالبات',10,1,'دريافت مطالبات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30112,651,'ثبت دريافت مطالبات',10,2,'دريافت مطالبات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30113,652,'ثبت  دريافت بدهي به تاريخ غيرجاري',10,3,'دريافت مطالبات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30115,653,'ويرايش دريافت مطالبات',10,4,'دريافت مطالبات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30116,654,'حذف دريافت مطالبات',10,5,'دريافت مطالبات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30120,655,' امکان حذف دريافت بدهي به تاريخ غيرجاري',10,6,'دريافت مطالبات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30181,656,'مجوز ثبت تخفيف در دريافت',10,6,'دريافت مطالبات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30019,670,'پرداخت بدهي',11,1,'پرداخت بدهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30109,671,'ثبت پرداخت بدهي',11,2,'پرداخت بدهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30110,672,'حذف پرداخت بدهي',11,3,'پرداخت بدهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30111,673,'ثبت پرداخت بدهي به تاريخ غيرجاري',11,4,'پرداخت بدهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30121,674,' امکان حذف پرداخت بدهي به تاريخ غيرجاري',11,5,'پرداخت بدهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30114,675,'ويرايش پرداخت بدهي',11,6,'پرداخت بدهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30184,676,'مجوز تخفيف در پرداخت',12,6,'پرداخت بدهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30020,690,'گزارش صندوق',16,26,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30168,691,'گزارش جامع دريافت',16,27,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30169,692,'گزارش جامع پرداخت',16,28,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30021,700,'ثبت درآمدها',13,1,'ثبت درآمدها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30117,701,'امکان حذف درآمد',13,2,'ثبت درآمدها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30118,702,'امکان ويرايش درآمد',13,3,'ثبت درآمدها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30119,703,' امکان حذف درآمد به تاريخ غيرجاري',13,4,'ثبت درآمدها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30201,704,'گزارش ليستي درآمد',13,5,'ثبت درآمدها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30022,710,'ثبت هزينه ها',14,1,'ثبت هزينه ها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30088,711,'گزارش هزينه ها ',14,2,'ثبت هزينه ها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30199,712,'مرور هزينه ها',14,3,'ثبت هزينه ها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30200,713,'گزارش ليستي هزينه ها',14,4,'ثبت هزينه ها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30023,720,'انتقال وجه',15,1,'انتقال وجه')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30208,721,'گزارش ليستي انتقال وجه',15,2,'انتقال وجه')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30024,730,'گزارش جامع فروش',16,1,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30080,731,'نمودار فروش',16,2,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30081,732,'نمودار مقايسه اي ويزيتورها',16,3,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40224,733,'مشتريان فاقد فاکتور',16,4,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40225,734,'گزارش فروش به تفکيک گروه کالا(برند)',16,5,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30025,740,'گزارش جامع خريد',16,6,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30026,750,'گزارش جامع برگشت از فروش',16,7,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30027,760,'گزارش جامع برگشت از خريد',16,8,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30028,770,'سند حسابداري',20,1,'سند حسابداري')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30084,771,'سود و زيان',65,1,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40227,772,'سود کالا',65,2,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40228,773,'گزارش سود کالا به تفکيک برند(گروه کالا)-فايفو',65,3,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30029,780,'ثبت سفارش غذا',21,1,'ثبت سفارش غذا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30030,790,'محل چاپگر',22,1,'محل چاپگر')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30031,795,'معرفي مشترکين',23,1,'معرفي مشترکين')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30032,800,'خدمات کارواش',24,1,'خدمات کارواش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30033,805,'معرفي راننده',25,1,'معرفي راننده')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30123,806,'حذف راننده',25,2,'معرفي راننده')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30124,807,'ويرايش راننده',25,3,'معرفي راننده')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40219,808,'اتصال راننده به انبار',25,4,'معرفي راننده')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30035,815,'گزارش عملکرد راننده',27,1,'گزارش عملکرد راننده')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30036,820,'ثبت سرويس',28,1,'ثبت سرويس')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30037,830,'معرفي مسير',29,1,'معرفي مسير')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30038,835,'در انتظار آي دي کالر',30,1,'در انتظار آي دي کالر')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30039,840,'معرفي دسته چک',36,1,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30040,845,'ثبت وصول چک',36,2,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30041,850,'واگذاري چک به بانک',36,3,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30042,855,'ثبت پاس چک خودمان',36,4,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30043,860,'گزارش بانک',36,5,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30044,865,'گزارش چکهاي دريافتي',36,6,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30082,866,'هشدار سررسيد چک',36,7,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40232,867,'برگشت چک دريافتي',36,8,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40233,868,'چکهاي دريافتي ابتداي دوره',36,9,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40234,869,'چکهاي پرداختي ابتداي دوره',36,9,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30045,870,'گزارش ليست اشخاص',16,9,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40236,871,'عودت چک فروخته شه',36,11,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40237,872,'بازپس گيري چک پرداختي',36,12,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40238,873,'گزارش چکهاي پرداختي',36,13,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40239,874,'چاپ روي چک',36,14,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30046,875,'گزارش ليست کالا',16,11,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30129,876,'چاپ ليست کالا',16,12,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40242,877,'ليست کالا چند قيمته ديناميک',16,13,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40243,878,'نرخنامه محصولات',16,14,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30047,880,'گزارش موجودي انبار',16,15,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40214,881,'گزارش موجودي انبار به تفکيک انبارها',16,16,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40215,882,'گزارش موجودي انبار به تفکيک تاريخ انقضاء',16,17,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40216,883,'گردش کالا',16,18,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30048,885,'کاردکس کالا',16,19,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30049,890,'گزارش صورتحساب اشخاص',16,20,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40244,891,'عملکرد مشتريان',16,21,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30050,895,'ليست بدهکاران',16,22,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30051,900,'ليست بستانکاران',16,23,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30052,905,'مانده حساب اشخاص',16,24,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30053,910,'عملکرد تفصيلي',65,16,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30054,915,'فاکتورهاي تسويه نشده',16,25,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30055,920,'معرفي کالا',47,1,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30127,921,'امکان حذف کالا',47,2,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30128,922,'امکان ويرايش کالا',47,3,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30136,923,'اشانتيون کالا',47,4,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30137,924,'چند قيمته',47,5,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30056,925,'گروه بندي کالا',48,1,'گروه بندي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30139,926,'اشانتيون گروهي کالا',48,7,'گروه بندي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40252,927,'اشانتيون مبلغي',47,6,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30057,930,'موجودي ابتداي دوره',49,1,'موجودي ابتداي دوره')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30058,935,'واحد اندازه گيري',50,1,'واحد اندازه گيري')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30059,940,'معرفي اشخاص',51,1,'معرفي اشخاص')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30130,941,'امکان حذف در معرفي اشخاص',51,2,'معرفي اشخاص')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30131,942,'امکان ويرايش در معرفي اشخاص',51,3,'معرفي اشخاص')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40217,943,'انتقال اشخاص به گروه ديگر',51,4,'معرفي اشخاص')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30060,945,'گروه بنده اشخاص',52,1,'گروه بنده اشخاص')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30061,950,'دفترچه تلفن',53,1,'دفترچه تلفن')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30125,951,'حذف در دفترچه تلفن',53,2,'دفترچه تلفن')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30126,952,'ويرايش در دفترچه تلفن',53,3,'دفترچه تلفن')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30062,955,'مانده ابتداي دوره اشخاص',54,1,'مانده ابتداي دوره اشخاص')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30063,960,'معرفي ويزيتور',55,1,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30140,961,'پورسانت هدفمند',55,1,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30141,962,'ويرايش پورسانت هدفمند',55,2,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30142,963,'حذف پورسانت هدفمند',55,3,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30143,964,'گزارش پورسانت هدفمند واريز',55,4,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30064,965,'معرفي سوپروايزر',55,6,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40220,966,'ارسال پيام به ويزيتور',55,5,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30065,970,'معرفي بانک مشتري',57,1,'معرفي بانک مشتري')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30066,975,'معرفي بانک ما',58,1,'معرفي بانک ما')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30067,980,'معرفي صندوق',59,1,'معرفي صندوق')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30132,981,'چاپ گزارش ليست اشخاص',16,10,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30068,985,'معرفي انبار',60,1,'معرفي انبار')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30069,990,'معرفي هزينه ها',61,1,'معرفي هزينه ها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30070,995,'معرفي درآمدها',62,1,'معرفي درآمدها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30071,1000,'پشتيبان گيري اطلاعات',63,1,'پشتيبان گيري اطلاعات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30072,1005,'بازيابي اطلاعات',63,1,'بازيابي اطلاعات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30073,1010,'پاک کردن اطلاعات',63,1,'پاک کردن اطلاعات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30074,1015,'تنظيمات چاپ',63,1,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30075,1020,'تنظيمات قفل',63,2,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30076,1025,'تنظيمات خريد و فروش',63,3,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30077,1030,'بروزرساني اطلاعات تبلت',63,4,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30078,1035,'بروزرساني ',63,5,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30079,1040,'ايجاد حساب جديد',63,6,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30083,1041,'تنظيمات کلي',63,7,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30102,1042,'امکان حذف انتقال کالا بين انبار',64,1,'انتقال کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30103,1043,'امکان ويرايش انتقال کالا بين انبار',64,2,'انتقال کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30104,1044,'امکان حذف انتقال کالا به تاريخ غيرجاري',64,3,'انتقال کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30105,1045,'امکان ويرايش انتقال کالا به تاريخ غيرجاري',64,4,'انتقال کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30166,1046,'معرفي سريع کالا در فرم ها',63,10,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30167,1047,'معرفي سريع اشخاص در فرم ها',63,9,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40262,1048,'دسترسي به گروه کالا',69,3,'مديريت شعب')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30133,1050,'معرفي تفصيلي',65,7,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30134,1051,'ويرايش تفصيلي',65,2,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30135,1052,'حذف تفصيلي',65,3,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30144,1053,'معرفي کل و معين',65,4,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30145,1054,'ويرايش کل و معين',65,5,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30146,1055,'حذف کل و معين',65,6,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30154,1056,'دفتر روزنامه',65,7,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30155,1057,'دفتر کل',65,8,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30179,1058,'صدور سند حسابداري به تاريخ غير جاري',65,9,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30193,1059,'گزارش ليستي اسناد',65,10,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30194,1060,'مرورحسابها',65,11,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30195,1061,'ترازآزمايشي',65,12,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30196,1062,'ترازنامه',65,13,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30197,1063,'جستجو در اسناد',65,14,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40221,1064,'بستن حسابها',65,15,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30138,1200,'چند قيمته ديناميک',47,8,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30159,1201,'قفل کردن فاکتورها',63,8,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30147,1210,'تخفيفات مبلغي',66,1,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30148,1211,'ويرايش تخفيفات مبلغي',66,2,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30149,1212,'حذف تخفيفات مبلغي',66,3,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30150,1213,'تخفيفات حجمي',66,4,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30151,1214,'ويرايش تخفيفات حجمي',66,5,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30152,1215,'حذف تخفيفات حجمي',66,6,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30187,1216,'توليد',67,1,'توليد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30188,1217,'حذف در توليد',67,2,'توليد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30189,1218,'ويرايش در توليد',67,3,'توليد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30190,1219,'فرمول توليد',67,4,'توليد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30191,1220,'حذف در فرمول توليد',67,5,'توليد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30192,1221,'ويرايش در فرمول توليد',67,6,'توليد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30211,1222,'غير الزامي بود اتصال فروش به برگشت از فروش',3,11,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (30212,1223,'غير الزامي بود کنترل ريز اقلام فروش',3,12,'برگشت از فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40222,1225,'تخفيفات حجمي گروهي کالا',66,7,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40245,1226,'حقوق و پورسانت ويزيتورها',55,7,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40246,1227,'گزارش پورسانت هدفمند',55,8,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40247,1228,'گزارش عملکرد ويزيتور',55,9,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40248,1229,'گزارش عملکرد ويزيتور2',55,10,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40235,1230,'بازپسگيري چک فروخته شده',36,10,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40251,1231,'انتقال کالاها به گروه ديگر',47,7,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40253,1232,'ارسال صورتحساب به سامانه موديان',69,1,'اختصاصي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40254,1233,'مرتب سازي اسناد',65,15,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40255,1234,'سامانه اتصال به بانک',36,15,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40256,1235,'نمايش متن پيامک در سامانه اتصال به بانک',36,16,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40257,1236,'نمايش مانده بانک در سامانه اتصال به بانک',36,17,'بانک')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40258,1237,'امکان ويرايش مبلغ در فرم دريافت',10,7,'دريافت مطالبات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40260,1238,'دسترسي به پرسنل',69,1,'مديريت شعب')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40261,1239,'دسترسي به گروه اشخاص',69,2,'مديريت شعب')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40263,1240,'ربات انتقال ديتا بين نرم افزارها',69,4,'مديريت شعب')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40264,1241,'حواله خروج کالا',14,5,'ثبت هزينه ها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40265,1242,'سفارش خريد',2,13,'خريد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40266,1243,'اتصال رابط به فاکتور',1,27,'فروش')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40267,1244,'گزارش عملکرد سفارشات ويزيتورها',6,3,'سفارشات ويزيتورها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40268,1245,'عملکرد رابط در اسناد پروژه اي',20,2,'سند حسابداري')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40269,1246,'ريز عملکرد رابط در اسناد پروژه اي',20,3,'سند حسابداري')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40270,1247,'گزارش عملکرد انباردار',9,10,'حواله گروهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40271,1248,'تور ويزيت',55,11,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40272,1249,'مديريت ويزيت',55,12,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40273,1250,'مدت تسويه کالايي',47,12,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40274,1251,'نمودار عملکرد ماهانه ويزيتور ',55,13,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40275,1252,'حواله گروهي و توزيع سفارشات ويزيتورها',9,11,'حواله گروهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40276,1253,'نمودار فروش روزانه ويزيتور',55,14,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40277,1254,'داشبورد عملکرد ويزيتورها',55,15,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40278,1255,'گزارش عملکرد ويزيتور 3',55,16,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40279,1256,'گزارش فروش و واريز ويزيتور',55,17,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40280,1257,'گزارش ريز واريزي ويزيتورها',55,18,'ويزيتور')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40281,1258,'گزارش ريز توليد',67,7,'توليد')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40282,1259,'محدوديت درصد تخفيف',66,8,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40283,1260,'تخفيفات نقدي',66,9,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40284,1261,'طرح تخفيفات رديفي',66,10,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40285,1262,'محدوديت مبلغي تخفيف',66,11,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40286,1263,'محدوديت درصد تخفيف دريافت',66,12,'تخفيفات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40287,1264,'مديريت باسکول',70,1,'ساير')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40288,1265,'گزارش جامع سفارشات',6,4,'سفارشات ويزيتورها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40289,1266,'سفارشات ويزيتورها در سرور',6,5,'سفارشات ويزيتورها')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40290,1267,'نمودار واريزي ماهيانه',70,2,'ساير')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40291,1268,'ثبت وام و اقساط',71,1,'اقساط')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40292,1269,'گزارش وام',71,2,'اقساط')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40293,1270,'گزارش جامع اقساط',71,3,'اقساط')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40294,1271,'گزارش اقساط معوقه',71,4,'اقساط')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40295,1272,'گزارش سود ويزيتور',65,15,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40296,1273,'گزارش خالص فروش',16,29,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40297,1274,'گزارش عملکرد راننده(پخش گرم)',16,30,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40298,1275,'انبارگرداني',70,3,'ساير')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40299,1276,'گزارش مغايرت گيري انبار',16,31,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40300,1277,'بستن حسابها',65,17,'مالي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40301,1278,'محدوديت دسترسي تبلت',63,11,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40302,1279,'گزارش عملکرد کاربران',63,12,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40303,1280,'ارتباط کدينگ اتوماتيک',63,13,'تنظيمات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40304,1281,'ارسال به سامانه
دفاتر الکترونيکي',69,2,'اختصاصي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40305,1282,'تغيير گروهي و کلي قيمتها',47,9,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40306,1283,'نوع تسويه',47,10,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40307,1284,'چند قيمته ديناميک',47,11,'معرفي کالا')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40308,1285,'گزارش سفارشي',16,32,'گزارشات')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40309,1286,'قفل نشدن عملياتها در محدوده زماني',70,4,'ساير')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40315,1287,'غير الزامي بودن گروه دوم اشخاص',51,5,'معرفي اشخاص')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40316,1288,'حساب به حساب',12,7,'پرداخت بدهي')
GO
INSERT INTO [dbo].[tblListeDastrasi] ([ID],[fldCode],[fldName],[fldGroup],[fldOrder],[fldNameGroup]) VALUES (40317,1289,'اشانتیون کالایی به تفکیک اشخاص و گروه مشتریان',47,13,'معرفي کالا')
GO

SET IDENTITY_INSERT [dbo].[tblListeDastrasi] OFF
GO

-- TABLE: tblMenuMaster
DELETE FROM [dbo].[tblMenuMaster]
GO

SET IDENTITY_INSERT [dbo].[tblMenuMaster] ON
GO

INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (242,'اتصال به جي اس ام مودم','connectgsm')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (278,'ارسال پيام به ويزيتور','sendnotification')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10337,'اشانتیون کالایی به تفکیک اشخاص و گروه مشتریان','a38')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (318,'اشانتيون گروه به گروه اندرويد','egg')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (162,'اشانتيون گروهي کالا','eshantiongoroohi')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (247,'اصلاح کلي فاکتورها','eslahekoliefactorha')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (254,'انبارگرداني','moghayeratanbar')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (151,'انتقال کالا بين انبار','enteghalekala')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (187,'انتقال وجه','enteghalevajh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (294,'بازپسگيري چک پرداختي','CheckBazPasDahiShode')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (280,'بازپسگيري چک فروخته شده','BargashteCheckeVagozarShode')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (239,'بازيابي اطلاعات','restor')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (176,'برگشت از خريد','bargashtazkharid')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (173,'برگشت از فروش','bargashtazforoosh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (164,'برگشت اسناد قطعي شده','bargashteghatei')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (307,'برگشت اماني','amnb')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (204,'برگشت چک دريافتي','bargashtecheck')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (181,'پرداخت','pardakht')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (238,'پشتيباني اطلاعات','backup')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (160,'پورسانت طبقاتي فروش','poorsantetabaghatiforoosh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (161,'پورسانت طبقاتي واريز','poorsantetabaghativariz')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (174,'پيش فاکتور','pishfactor')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (157,'تخفيفات حجمي','takhfifatehajmi')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (156,'تخفيفات مبلغي','takhfifatemablaghi')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (288,'تخفيفات نقدي','takhfifatenaghdi')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (293,'ترازآزمايشي','tarazeazmayeshi')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (265,'ترازنامه','tarazname')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (299,'تغيير گروهي و کلي قيمتها','changegoroohifee')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (243,'تنظيمات چاپ','tanzimatechap')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (244,'تنظيمات خريد و فروش','kharidvaforoosh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10326,'تور ويزيت','a18')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (153,'توليد','tolid')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (201,'ثبت پاس چکهاي خودمان','sabtepasecheck')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (183,'ثبت درآمد','sabtedaramad')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (261,'ثبت وام','vam')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (203,'ثبت وصول چک','sabtevosoolecheck')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (185,'ثبت هزينه','sabtehazine')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (283,'جستجو در اسناد','jostojoo')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (196,'چاپ چک','chapecheck')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (256,'چاپ سند','chapesanad')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (248,'چند قيمته ديناميک','multifeedynamic')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (170,'حذف اسناد','deleteasnad')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10336,'حساب به حساب','a36')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (320,'حواله خروج کالا','a11')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (322,'حواله گروهي سفارشات ويزيتورها','a13')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (177,'حواله گروهي-توزيع','havalegoroohi')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (321,'داشبورد عملکرد ويزيتورها','a12')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (180,'دريافت','daryaft')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10329,'دسترسي به پرسنل','Dastrasipersonel')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (279,'دسترسي به گروه اشخاص','DastrasigroupAshkhas')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (264,'دسترسي به گروه کالا','dastrasibegroupkala')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (168,'دفتر روزنامه','daftareroozname')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (167,'دفتر کل','daftekol')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (226,'دفترچه تلفن','daftarchetelephon')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10331,'رابط فروش','a23')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10334,'ريز عملکرد رابط در اسناد پروژه اي','a27')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (313,'ساير پرداختها','sayerpardakht')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10330,'سفارش خريد','a22')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (178,'سفارشات ويزيتورها','sefareshatevizitor')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (171,'سند افتتاحيه','eftetahie')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (325,'سند تجميعي','snt')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (195,'سند حسابداري','sanadehesabdari')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (249,'شرح چند قيمته ديناميک','sharhemultifee')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (166,'شرکت جديد','newcompany')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (212,'صورتحساب اشخاص','soorathesabeashkhas')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (245,'طراحي بارکد','barcode')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (251,'طرح تخفيفات حجمي','takhfifatehajmi')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (289,'طرح تخفيفات حجمي گروهي کالا','tarhetakhfifatehajmigoroohiekala')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (301,'طرح تخفيفات رديفي','tara')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (252,'طرح تخفيفات مبلغي','takhfifatemablaghi')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (237,'طول حسابهاي پايه','toolepaye')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (208,'عملکرد تفصيلي','almalkardetafzili')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10333,'عملکرد رابط در اسناد پروژه اي','a26')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (163,'عملکرد مراکز','amalkardemarakez')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (281,'عودت چک فروخته شده','OdateCheck')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (175,'فاکتور خريد','kharid')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (206,'فاکتورهاي تسويه نشده','factorhayetasfienashode')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (154,'فرمول توليد','formooletolid')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (172,'فروش','foroosh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (306,'فروش اماني','amnf')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (309,'فروشگاهي سطح1','forooshgahi1')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (215,'کاردکس کالا','kardeks')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (314,'کپي اسناد','cps')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (165,'کنترل اسناد','controleasnad')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (216,'گردش کالا','gardeshekala')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (285,'گزارش اقساط معوقه','reportaghsatmoavaghe')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (200,'گزارش بانک','reportbank')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (260,'گزارش به تفکيک گروه کالا (برند)','betafkikeberand')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (155,'گزارش پورسانت هدفمند','reportpoorsanthadafmand')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (284,'گزارش جامع اقساط','reportjameaghsat')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (192,'گزارش جامع برگشت از خريد','reportbargashtazkharid')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (193,'گزارش جامع برگشت از فروش','reportbargashtazforoosh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (263,'گزارش جامع پرداخت','reportpardakht')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (191,'گزارش جامع خريد','reportkharid')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (262,'گزارش جامع دريافت','reportdaryaft')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (188,'گزارش جامع فروش','reportforoosh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (198,'گزارش چکهاي پرداختي','reportcheckpardakhti')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (197,'گزارش چکهاي دريافتي','reportcheckdaryafti')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (297,'گزارش حقوق و پورسانت ويزيتور','reporthoghooghvizitor')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (253,'گزارش خالص فروش','reportkhalesforoosh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (184,'گزارش درآمد','reportdaramad')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (310,'گزارش ريز توليد','reportrizetolid')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (312,'گزارش ريز واريزي ويزيتورها','rvv')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10335,'گزارش سفارشي','a28')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (250,'گزارش سود کالا','reportsoodekala')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (277,'گزارش سود کالا به تفکيک برند(گروه کالا)-فايفو','reportsoodgroupkalafifo')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (194,'گزارش سود و زيان','soodozian')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (298,'گزارش سود ويزيتور','soodevizitor')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (182,'گزارش صندوق','reportsandoogh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10328,'گزارش عملکرد انباردار','a21')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (213,'گزارش عملکرد تفصيلي مراکز','reportamalkardetafziliemarakez')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10332,'گزارش عملکرد سفارشات ويزيتورها','a25')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (300,'گزارش عملکرد فصلي-TTMS','ttms')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (149,'گزارش عملکرد ويزيتور2','reportamalkardevizitor2')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (308,'گزارش عملکرد ويزيتور3','rv3')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (257,'گزارش عملکرد ويزيتورها','reportamalkardevizitor')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (311,'گزارش فروش و واريز ويزيتور','rfv')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (218,'گزارش ليست اشخاص','listeashkhas')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (272,'گزارش ليست انتقال کالا بين انبار','reportlistenteghalekala')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (276,'گزارش ليستي اسناد','reportlistasnad')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (275,'گزارش ليستي انتقال وجه','reportlistenteghalevajh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (268,'گزارش ليستي برگشت از خريد','reportlistbargashtazkharid')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (270,'گزارش ليستي برگشت از فروش','reportlistbargashtazforoosh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (271,'گزارش ليستي پيش فاکتور','reportlistpishfactor')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (267,'گزارش ليستي خريد','reportlistkharid')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (273,'گزارش ليستي درآمد','reportlistdaramad')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (269,'گزارش ليستي فروش','reportlistforoosh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (274,'گزارش ليستي هزينه','reportlisthazine')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (214,'گزارش موجودي انبار','reportanbar')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (186,'گزارش هزينه','reporthazine')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (255,'ليست اشخاص فاکتور نشده','reportlisteashkhasefactornashode')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (210,'ليست بدهکاران','listebedehkaran')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (211,'ليست بستانکاران','listebestankaran')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (217,'ليست کالا','listekala')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (282,'ليست کالا چند قيمته ديناميک','chapkalaMulti')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (225,'مانده ابتداي دوره اشخاص','mandeebtedaashkhas')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (209,'مانده حساب اشخاص','mandehesaeashkhas')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (302,'محدوده درصد تخفيف','lmtak')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (305,'محدوده درصد تخفيف دردريافت','tkdar')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (241,'محدوديت دسترسي تبلت','dastresietablet')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (303,'محدوديت مبلغي تخفيف','lmtam')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (326,'مدت تسويه کالايي','a17')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (319,'مديريت باسکول','bas')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (10327,'مديريت ويزيت','a19')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (246,'مرتب سازي فاکتورها به ترتيب تاريخ','moratabsazifactortarikh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (169,'مرور حسابها','moroorehesabha')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (259,'مرور هزينه ها','moroorehazineha')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (179,'مسير حرکت ويزيتور','masireharekatevizitor')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (227,'معرفي اشخاص','moarefieashkhas')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (234,'معرفي انبار','anbar')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (232,'معرفي بانک ما','bankema')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (233,'معرفي بانک مشتري','bankemoshtari')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (230,'معرفي تفصيلي','moarefietafzili')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (258,'معرفي چاپگر','moarefiechapgar')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (158,'معرفي حسابهاي کل و معين','kolmoin')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (236,'معرفي درآمدها','moarefiedaramadha')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (205,'معرفي دسته چک','dastecheck')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (229,'معرفي راننده','moarefieranande')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (159,'معرفي سوپر وايزر','supervizor')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (231,'معرفي صندوق','moarefiesandoogh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (240,'معرفي کاربر','moarefiekarbar')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (222,'معرفي کالا','moarefiekala')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (228,'معرفي گروه اشخاص','groupashkhas')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (223,'معرفي گروه کالا','groupkala')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (224,'معرفي ويزيتور','vizitor')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (235,'معرفي هزينه ها','moarefiehazineha')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (221,'موجودي ابتداي دوره','mojoodieebtedayedooreanbar')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (286,'موقعيت مکاني مشتريان روي نقشه','locationmoshtari')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (317,'نرخنامه محصولات','nerkhname')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (324,'نرم افزار اموال و جمعداري','a14')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (316,'نرم افزار حقوق و دستمزد','hgd')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (266,'نرم افزار مالي','mali')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (189,'نمودار فروش','nemoodareforoosh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (323,'نمودار فروش ماهانه ويزيتور','a1')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (190,'نمودار مقايسه اي ويزيتورها','nemoodaremoghayeseeivizitorha')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (152,'نمودار واريزي ويزيتورها','nemoodarevarizevizitor')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (220,'واحد اندازه گيري','vahedeandazegiri')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (202,'واگذاري چک به بانک','vagozariecheck')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (150,'وضعيت تسويه حواله','vaziatetasfiehavale')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (219,'هشدار سررسيد تاريخ','lalarmetarikh')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (199,'هشدار سررسيد چک','alarmecheck')
GO
INSERT INTO [dbo].[tblMenuMaster] ([ID],[fldNameFarsi],[fldNameEnglish]) VALUES (207,'هشدار سررسيد فاکتورهاي تسويه نشده','alarmsarresiefactor')
GO

SET IDENTITY_INSERT [dbo].[tblMenuMaster] OFF
GO

-- TABLE: tblVersionInfo
DELETE FROM [dbo].[tblVersionInfo]
GO

SET IDENTITY_INSERT [dbo].[tblVersionInfo] ON
GO

INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (2,14011004,'اضافه شدن جستجوهاي جديد به گزارش چکهاي دريافتي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (3,14011004,'اضافه شدن تاريخ فاکتور در گزارش فاکتورهاي تسويه نشده در حالت چاپ','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (4,14011006,'اضافه شدن قابليت اتصال به دستگاه پوز بانکي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (5,14011001,'اضافه شدن جستجوهاي بيشتر در گزارش چکهاي دريافتي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (6,14011017,'اضافه شدن جمع مبلغ چکهاي واگذاري در فرم واگذاري چک به بانک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (7,14011018,'بزرگنمايي در گزارش جامع فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (8,14011019,'اضافه شدن موزع در حواله گروهي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (9,14011019,'ذخيره کردن آدرس مسير پشتيبان براي تسريع در امر پشتيبان گيري','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (10,14011020,'مجوز ثبت مجدد فاکتوري که قبلا حواله شده است','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (11,14011025,'اضافه کردن محدوده تاريخي در گزارش سود کالا براساس ميانگين خريد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (12,14011027,'اضافه شدن گزارش سود ويزيتور در محدوده تاريخي','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (13,14011028,'جستجوي نام ويزيتور در فرم فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (16,14011117,'رفع يک ايراد در نرم افزار','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (17,14011118,'اضافه شدن شماره شبا در فرم چک دريافتي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (18,14011201,'اضافه شدن شماره صيادي در مشخصات چک دريافتي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (19,14011202,'امکان تغيير تعداد جزء در معرفي کالا در حالتي که عملکرد دارد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20,14011206,'رفع اشکال در اشانتيون کالايي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (21,14011207,'اضافه شدن امکان فروش به ويزيتور و پرسنل','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (22,14011211,'توسعه گزارش تسويه حواله','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (23,14011211,'اضافه شدن نام منطقه در ليست فاکتورها در حواله گروهي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (10022,14011211,'مجوز فروش به شخصي که بدهي قبلي دارد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (10023,14011213,'تغيير گروهي و کلي قيمت هاي کالا','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (10024,14011221,'اضافه شدن ميانبر ارزش افزوده در فرم فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (10025,14011221,'اضافه شدن ميانبر ارزش افزوده در فرم خريد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20024,14011222,'رفع يک ايراد کوچک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20025,14020106,'نمايش سال مالي در فرم اصلي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20026,14020106,'امکان تغيير سال مالي در فرم ورود','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20027,14020213,'گزارش عملکرد فصلي-TTMS','افزونه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20028,14020213,'فعال شدن طرح تخفيفات مبلغي در برگشت از فروش','افزونه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20029,14020220,'افزودن دسترسي هاي جديد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20030,14020225,'رفع يک خطاي کوچک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20031,14020228,'افزونه ارسال صورتحساب به سامانه موديان مالياتي','افزونه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20032,14020310,'اضافه شدن بروز شدن في فروش در سفارشات ويزيتور','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20033,14020322,'نمايش اعتبار پيامکي ','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20034,14020323,'قابليت اتصال به دستگاه پوز شرکت پارسيان','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20035,14020323,'امکان تغيير تاريخ سررسيد فاکتور در حواله گروهي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20036,14020325,'قابليت قفل کردن دريافت و پرداخت','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20037,14020327,'اضافه شدن طرح تخفيفات رديفي','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20038,14020401,'افزونه محدود کردن درصد تخفيف','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20039,14020401,'توسعه افزونه انتقال گروهي کالا','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20040,14020401,'توسعه افزونه انتقال گروهي اشخاص','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20041,14020505,'افزونه محدود کردن مبلغ تخفيف','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20042,14020510,'افزونه محدود کردن درصد تخفيف در فرم دريافت','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20043,14020515,'ايرادات در انبار','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20044,14020516,'فروش اماني','افزونه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20045,14020516,'کنترل عملکرد کاربر در سفارشات ويزيتور و اعمال چندين قابليت کنترلي جديد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20046,14020517,'امکان غيرفعال کردن گزينه بدهکار در فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20047,14020523,'رنگ بندي و توضيحات در گزارش فاکتورهاي تسويه نشده','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20048,14020524,'اضافه شدن کد کالا به صورت دستي در معرفي کالا','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20049,14020525,'اضافه شدن گزارش فروش بدون واسطه در گزارش جامع فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20050,14020525,'اضافه شدن گزارش فروش بدون واسطه در گزارش خالص فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20051,14020530,'اضافه شدن وضعيت تبديل در سفارشات ويزيتور','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20052,14020601,'اضافه شدن فيلتر کردن سفارشات تبديل شده و نشده در گزارش سفارشات ويزيتور','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20053,14020602,'جستجوي آدرس در انتقال گروهي اشخاص','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20054,14020602,'جستجوي نام کالا در انتقال گروهي کالا','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20055,14020604,'قابليت نمايش و چاپ مشتريان  ويزيتور و يا مشتريان به تفکيک منطقه','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (14,14011103,'پر شدن اتوماتيک في خريد کالا در فرم خريد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (15,14011104,'اضافه شدن درصد تخفيف ثابت براي مشتريان','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20056,14020626,'قابليت قفل کردن اتوماتيک فاکتور با ثبت فاکتور','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20058,14020629,'قابليت الزامي کردن انتخاب ويزيتور در دريافت','پخش')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20059,14020704,' نمايش سفاشات ويزيتور در سرور اندرويد','پخش')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20060,14020704,'قابليت فعال و غيرفعال کردن اندرويد ويزيتور توسط کاربر','پخش')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20061,14020714,'اضافه کردن محدوديت نمايش موجودي مثبت در فرم نرخنامه محصولات ','پخش')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20062,14020724,'امکان طراحي فاکتور در خود نرم افزار','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20063,14020816,'اضافه کردن سه صفر براي مبلغ با فشار روي دکمه + در کيبورد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20064,14020816,'اضافه شدن اتوماتيک فاکتورهاي ويرايش شده بعد از بروزرساني','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20057,14020626,'قابليت فعال و غيرفعال کردن ويزيتور','پخش')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20065,14020820,'گزارش عملکرد ويزيتور 3','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20068,14020915,'کپي اسناد و امکان انتقال آن','مالي')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20069,14020929,'توسعه سامانه بانکي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20070,14020929,'اضافه شدن نمودار خالص فروش و برگشت از فروش  کل','ماژول مشترک')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20071,14020929,'اضافه شدن نمودار خالص فروش و برگشت از فروش  ويزيتورها','ماژول مشترک')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20072,14021110,'توسعه گزارش فاکتورهاي تسويه نشده','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20073,14021110,'افزايش اعتبار اشخاص به صورت گروهي','افزونه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20074,14021115,'کنترل سقف فروش ويزيتور','افزونه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20075,14021124,'توسعه گزارش عملکرد ويزيتورها','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20076,14021125,'خروجي سامانه تجارت','افزونه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20077,14021126,'توسعه گزارش پورسانت طبقاتي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20078,14021224,'نمودار عملکرد ماهانه ويزيتور ','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20079,14030125,'افزودن موجودي ابتداي دوره بانک با سند اتوماتيک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20080,14030126,'امکان تغيير شماره فاکتور خريد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20081,14030126,'امکان تغيير شماره فاکتور فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20082,14030130,'گزارش و چاپ چکهاي واگذار شده به بانک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20083,14030220,'نسخه جديد صدور سند','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20084,14030301,'امکان اضافه کردن صفر در ابتداي شماره چک دريافتي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20085,14030305,'چاپ ليست کل و معين','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20086,14030309,'ليست مشتريان بدون ويزيتور','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20087,14030309,'اتصال گروهي مشتريان به يک ويزيتور ','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20088,14030312,'قابليت اجراي همزمان چند نسخه نرم افزار','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20089,14030321,'اضافه شدن مرتب سازي در گزارش عملکرد مشتريان','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20090,14030321,'اضافه شدن بانک پاسارگاد به سامانه پيامکي بانک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20091,14030327,'جستجوي چک براساس نام صاحب در فرم وصول چک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20092,14030327,'جستجوي چک براساس نام صاحب در فرم خواباندن چک به بانک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20093,14030327,'جستجوي چک براساس نام دريافت کننده در فرم پاس چک خودمان','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20094,14030327,'جستجوي چک براساس نام دريافت کننده در فرم چکهاي واگذارشده','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20095,14030327,'جستجوي چک براساس نام دريافت کننده در فرم برگشت چک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20096,14030327,'جستجوي چک براساس نام در فرم چکهاي دريافتي ابتداي دوره ','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20097,14030327,'جستجوي چک براساس نام در فرم چکهاي پرداختي ابتداي دوره ','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20098,14030330,'سند تجميعي روزانه و ماهانه','مالي')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20099,14030403,'کپي دسترسي هاي يک کاربر براي کاربر ديگر','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20100,14030410,'توسعه فرم صدور سند جديد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20101,14030417,'سند حسابداري براي عمليات توليد','توليد')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20102,14030417,'گزارش اسناد حسابداري توليد','توليد')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20103,14030423,'ترازآزمايشي 8 ستونه','مالي')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20104,14030424,'جستجوي فاکتور در موديان','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20105,14030506,'توسعه جستجو در فرم واگذاري چک به بانک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20106,14030508,'قابليت جابجايي رديف سند  در فرم سند حسابداري','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20107,14030514,'توسعه گزارش وضعيت تسويه حواله','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20108,14030530,'نمودار مقايسه اي واريز و برداشت','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20109,14030606,'اضافه شدن واترمارک در چاپ فاکتور','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20110,14030610,'توسعه توليد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20111,14030613,'افزودن قابليت رنگ بندي براي واترمارک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20112,14030625,'قابليت تغييرات در جداول فرمها','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20113,14030626,'افزايش دقت محاسبه سود و زيان در حالت فايفو','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20114,14030705,'اضافه شدن کپي سند در سند حسابداري','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20115,14030708,'توسعه گزارش عملکرد ويزيتور3','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20116,14030708,'خروجي اکسل فوري در گزارشات','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20117,14030711,'افزونه حجم بارگيري','افزونه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20118,14030714,'نمايش شناسه کالا در جدول در معرفي کالا','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20119,14030714,'شماره حواله در فاکتور فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20120,14030715,'اضافه شدن جستجو براساس نام شخص و کد شخص در موديان','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (30120,14030716,'توسعه و رفع اشکال در فرم انبارگرداني','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (30121,14030717,'اضافه شدن راس گيري چک براي چکهاي دريافتي و پرداختي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (30122,14030721,'اضافه شدن شماره صياد و شماره شبا در گزارش چکهاي دريافتي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (30123,14030721,'اضافه شدن شماره بازپسگيري در گزارش چکهاي دريافتي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (30124,14030721,'اضافه شدن شماره عودت چک در گزارش چکهاي دريافتي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (30125,14030721,'اضافه شدن شماره بازپسگيري چک پرداختي در گزارش چکهاي پرداختي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40122,14030805,'مديريت باسکول','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40123,14030808,'ارتباط کدينگ اتوماتيک','پخش 2 و 3 و بازرگاني 3')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40124,14030809,'کنترل في خريد به تفکيک انبار در فاکتور فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40125,14030810,'قابليت محدود کردن اندرويد ويزيتور به يک انبار در فرم دسترسي تبلت','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40126,14030813,'ماشين حساب هوشمند و حرفه اي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40127,14030816,'راه اندازي سطح 4','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40129,14030905,'توسعه گزارش پورسانت هدفمند','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40130,14030907,'آخرين تاريخ فروش و دريافت در ليست بدهکاران و بستانکاران','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40128,14030816,'مجوز فروش و عدم فروش با في صفر','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20066,14020828,'مشاهده ريز تغييرات فاکتور فروش در معرفي کاربر','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (20067,14020914,'اضافه شدن ثبت کارمزد بانک در پرداخت','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40131,14030910,'قابليت اتصال به دستگاه پوز بانک ملت','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40132,14030917,'ارسال پيامک پيش فاکتور براي سوپروايزر','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40133,14030918,'نمايش مانده صندوق و بانک در فرم پرداخت و کنترل بيشتر از موجودي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40134,14030919,'اضافه شدن تعداد و ريز شماره فاکتورها در چاپ حواله گروهي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40135,14030920,'شکل جديد چاپ ترازنامه','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40136,14031001,'فيلتر نمايش اشانتيونها در گزارش جامع فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40137,14031001,'فيلتر نمايش اقلام با مبلغ صفر در گزارش جامع فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40138,14031001,'فيلتر نمايش اقلام داراي ارزش افزوده در گزارش جامع فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40139,14031004,'اضافه شدن کد نقش براي خروجي سامانه تجارت الکترونيک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40140,14031008,'اضافه شدن توضيحات در معرفي اشخاص','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40141,14031008,'اضافه شدن فيلتر بيشتر از مبلغ تسويه در گزارش فاکتورهاي تسويه نشده','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40142,14031012,'افزونه خروج کالا ','سطح 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40143,14031013,'افزونه حواله گروهي براساس سفارشات ويزيتورها ','سطح 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40144,14031015,'افزونه داشبورد عملکرد ويزيتورها','سطح 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40145,14031018,'اضافه شدن حق تاهل و پايه سنوات براي توليد فايل بيمه براساس قوانين جديد','حقوق دستمزد')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40146,14031024,'فيلتر براساس شماره فاکتور در گزارش وضعيت تسويه حواله','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40147,14031024,'قابليت ارسال پيامک خلاصه فاکتور در حواله گروهي براي سوپروايزر','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40148,14031026,'فعال و غير فعال کردن بانک','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40149,14031026,'فعال و غيرفعال کردن صندوق','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (40150,14031029,'اضافه شدن پايه سنوات در فيش حقوقي','حقوق دستمزد')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (50150,14031120,'گزارش مغايرت گيري انبار','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (50151,14031124,'اضافه شدن فاکتور رسمي A5 در فاکتور فروش','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (50152,14031127,'اضافه شدن بانک مسکن به سامانه بانکي','افزونه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (50153,14031208,'الزام کردن ويزيتور به ثبت سفارش در محل مشتري','سفارشگير اندرويد')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (50154,14031214,'راس چکهاي انتخابي در گزارش چکهاي دريافتي','افزونه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (50155,14031228,'الزامي کردن ثبت سفارش توسط ويزيتور در محل مشتري','اندرويد')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (50156,14040127,'کپي و انتقال فاکتور','سطح 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (50157,14040210,'ماژول ارسال به سامانه دفاتر تجارت الکترونيکي','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (50158,14040213,'اضافه شدن فيلتر براساس ويزيتور در گزارش مشتريان فاقد فاکتور','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (50159,14040213,'اضافه شدن شماره تماس در گزارش مشتريان فاقد فاکتور','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (50160,14040313,'مدت تسويه کالايي','پخش 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (60160,14040313,'تور ويزيت','پخش 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (60161,14040313,'مديريت ويزيت','پخش 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (60162,14040429,'تغيير تاريخ ارسال موديان','موديان')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (60163,14040507,'محدود کردن تعداد روز براي طرح تخفيفات نقدي','پخش 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (60164,14040507,'کنترل عدم تجاوز تاريخ راس چک از تاريخ سررسيد فاکتور','پخش 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (60165,14040513,'ارزش افزوده کالايي در خريد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (60166,14040513,'افزايش سرعت نمايش موقعيت مکاني مشتريان روي نقشه','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (70165,14040516,'گروه دوم در معرفي اشخاص','پخش 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (70166,14040516,'افزايش سرعت در فرم نمايش موقعيت مکاني ويزيتورها','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (70167,14040520,'مجوز دسترسي به صورت حساب همه اشخاص در اندرويد','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (70168,14040520,'مجوز تغيير لوکيشن مشتريان','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (70169,14040525,'انباردار در حواله گروهي','پخش 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (70170,14040525,'گزارش انباردار','پخش 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (70171,14040525,'کنترل شناسه ملي در سامانه تجارت ','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (70172,14040608,'افزودن پرداخت به پرسنل در سامانه بانکي','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (70173,14040612,'بروزکردن آخرين تغييرات در سامانه تجارت','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80173,14040616,'خروجي اکسل ويژه اُکالا','همه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80174,14040616,'محدود کردن دسترسي يه پرسنل در صورتحساب','مديريت شعب')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80175,14040624,'سفارش خريد','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80176,14040726,'رابط فروش','سطح 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80177,14040727,'انتقال وجه در سامانه بانکي','افزونه')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80178,14040730,'قفل کردن اتوماتيک عملياتها تا تعداد روز مشخص','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80179,14040805,'گزارش عملکرد سفارشات ويزيتورها','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80182,14040817,'سند تجميعي ماهيانه دفاتر الکترونيکي','ماژول')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80181,14040813,'رابط اسناد پروژه اي','سطح 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80183,14040817,'افزايش اتوماتيک در مغايرت گيري','ماژول')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80184,14040825,'گزارشات سفارشي','سطح 3 و 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80185,14040905,'اضافه کردن تعداد در گزارش فروش به تفکيک برند','ماژول')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80186,14040909,'توسعه تور ويزيت','سطح 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80187,14040921,'ماژول ريموت پارسيک','همه سطوح')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80188,14040921,'بچ نامبر','سطح 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80189,14040921,'فاکتور دارويي و غذايي','همه ')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80190,14040929,'تاريخ ساخت محصول','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80191,14041002,'حساب به حساب','سطح4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80192,14041009,'راس فاکتورها در دریافت','سطح 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80193,14041009,'اشانتیون کالایی به تفکیک اشخاص و گروه مشتریان','سطح 4')
GO
INSERT INTO [dbo].[tblVersionInfo] ([ID],[fldVersion],[fldTozihat],[fldSath]) VALUES (80194,14041016,'توسعه حمل و نقل در فاکتور خرید','همه')
GO

SET IDENTITY_INSERT [dbo].[tblVersionInfo] OFF
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[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 = "tblEshantionGroupTabaghati"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 220
               Right = 243
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblKala"
            Begin Extent = 
               Top = 6
               Left = 281
               Bottom = 236
               Right = 508
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblGroupKala"
            Begin Extent = 
               Top = 6
               Left = 546
               Bottom = 205
               Right = 716
            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 = 2700
         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'viewGetListEshantionGroupTabalaghtis'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'viewGetListEshantionGroupTabalaghtis'
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[37] 4[13] 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 = "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 = 186
               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[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 = -96
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblTafzili"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 265
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblTafzili_1"
            Begin Extent = 
               Top = 138
               Left = 38
               Bottom = 267
               Right = 265
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      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'dbo', @level1type=N'VIEW',@level1name=N'viewLoadVizitor'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @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[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



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].[tblControlPanel]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblControlPanel](
	[fldLastMah] [nvarchar](3) NULL,
	[fldMaheDarhaleEjra] [nvarchar](3) NULL,
	[fldSaleMali] [nvarchar](2) NULL,
	[fldNameSherkat] [nvarchar](50) NULL,
	[fldNumberPooste] [nvarchar](50) NULL,
	[fldDateVersion] [nvarchar](10) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblEidi]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblEidi](
	[fldCodePersonel] [nvarchar](10) NULL,
	[fldMablagh] [nvarchar](10) NULL,
	[fldTedadRooz] [nvarchar](3) NULL,
	[fldMaliat] [nvarchar](10) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblErtebateKoding]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblErtebateKoding](
	[fldMosaede1] [nvarchar](10) NULL,
	[fldMosaede2] [nvarchar](10) NULL,
	[fldMosaede3] [nvarchar](10) NULL,
	[fldMosaede4] [nvarchar](10) NULL,
	[fldMosaede5] [nvarchar](10) NULL,
	[fldBime1] [nvarchar](10) NULL,
	[fldBime2] [nvarchar](10) NULL,
	[fldBime3] [nvarchar](10) NULL,
	[fldBime4] [nvarchar](10) NULL,
	[fldBime5] [nvarchar](10) NULL,
	[fldBime6] [nvarchar](10) NULL,
	[fldMaliat1] [nvarchar](10) NULL,
	[fldMaliat2] [nvarchar](10) NULL,
	[fldMaliat3] [nvarchar](10) NULL,
	[fldMaliat4] [nvarchar](10) NULL,
	[fldMaliat5] [nvarchar](10) NULL,
	[fldMaliat6] [nvarchar](10) NULL,
	[fldKasr1] [nvarchar](10) NULL,
	[fldKasr2] [nvarchar](10) NULL,
	[fldKasr3] [nvarchar](10) NULL,
	[fldKasr4] [nvarchar](10) NULL,
	[fldKasr5] [nvarchar](10) NULL,
	[fldKasr6] [nvarchar](10) NULL,
	[fldVam1] [nvarchar](10) NULL,
	[fldVam2] [nvarchar](10) NULL,
	[fldVam3] [nvarchar](10) NULL,
	[fldVam4] [nvarchar](10) NULL,
	[fldVam5] [nvarchar](10) NULL,
	[fldSayereBimeha1] [nvarchar](10) NULL,
	[fldSayereBimeha2] [nvarchar](10) NULL,
	[fldSayereBimeha3] [nvarchar](10) NULL,
	[fldSayereBimeha4] [nvarchar](10) NULL,
	[fldSayereBimeha5] [nvarchar](10) NULL,
	[fldSayereBimeha6] [nvarchar](10) NULL,
	[fldKhalesePardakhti1] [nvarchar](10) NULL,
	[fldKhalesePardakhti2] [nvarchar](10) NULL,
	[fldKhalesePardakhti3] [nvarchar](10) NULL,
	[fldKhalesePardakhti4] [nvarchar](10) NULL,
	[fldKhalesePardakhti5] [nvarchar](50) NULL,
	[fldKhalesePardakhti6] [nvarchar](50) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblForReport]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblForReport](
	[fldCodePersonel] [nvarchar](20) NULL,
	[fldKarkard] [nvarchar](8) NULL,
	[fldEzafeKar] [nvarchar](8) NULL,
	[fldTatilKar] [nvarchar](8) NULL,
	[fldJomeKar] [nvarchar](8) NULL,
	[fldKasreKar] [nvarchar](8) NULL,
	[fldEstehghaghi] [nvarchar](8) NULL,
	[fldEstelaji] [nvarchar](8) NULL,
	[fldGheibat] [nvarchar](8) NULL,
	[fldBedooneHoghoogh] [nvarchar](8) NULL,
	[fldShift] [nvarchar](7) NULL,
	[fldAyameMamooriat] [nvarchar](8) NULL,
	[fldHagheMamooriat] [nvarchar](20) NULL,
	[fldAlalHesab] [nvarchar](20) NULL,
	[fldPadash] [nvarchar](20) NULL,
	[fldSayereMotalebat] [nvarchar](20) NULL,
	[fldMosaede] [nvarchar](20) NULL,
	[fldSahmeSandoogh] [nvarchar](20) NULL,
	[fldMah] [nvarchar](2) NULL,
	[fldBimeSahmeKargar] [nvarchar](20) NULL,
	[fldMaliateHoghoogh] [nvarchar](20) NULL,
	[fldKasrekarKol] [nvarchar](20) NULL,
	[fldJameHoghooghVaMazaya] [nvarchar](20) NULL,
	[fldKhalesePardakhti] [nvarchar](20) NULL,
	[fldDastmozdeMahane] [nvarchar](20) NULL,
	[fldEzafeKari] [nvarchar](20) NULL,
	[fldTatilKari] [nvarchar](20) NULL,
	[fldNobatKari] [nvarchar](20) NULL,
	[fldJomeKari] [nvarchar](20) NULL,
	[fld1] [nvarchar](20) NULL,
	[fld2] [nvarchar](20) NULL,
	[fld3] [nvarchar](20) NULL,
	[fld4] [nvarchar](20) NULL,
	[fld5] [nvarchar](20) NULL,
	[fld6] [nvarchar](20) NULL,
	[fld7] [nvarchar](20) NULL,
	[fld8] [nvarchar](20) NULL,
	[fld9] [nvarchar](20) NULL,
	[fld10] [nvarchar](20) NULL,
	[fld11] [nvarchar](20) NULL,
	[fld12] [nvarchar](20) NULL,
	[fld13] [nvarchar](20) NULL,
	[fld14] [nvarchar](20) NULL,
	[fld15] [nvarchar](20) NULL,
	[fld16] [nvarchar](20) NULL,
	[fld17] [nvarchar](20) NULL,
	[fldName] [nvarchar](30) NULL,
	[fldFamily] [nvarchar](40) NULL,
	[fldShomareShenasname] [nvarchar](15) NULL,
	[fldMashmooleBime] [nvarchar](20) NULL,
	[fldSayereKosoor] [nvarchar](20) NULL,
	[fldMashmooleMaliat] [nvarchar](20) NULL,
	[fldShomareBime] [nvarchar](12) NULL,
	[fldShoghl] [nvarchar](30) NULL,
	[fldNamePedar] [nvarchar](30) NULL,
	[fldDateEstekhdam] [nvarchar](10) NULL,
	[fldDateTark] [nvarchar](10) NULL,
	[fldShomareHesab] [nvarchar](30) NULL,
	[fldCodeKargah] [nvarchar](15) NULL,
	[fldKargar1] [nvarchar](20) NULL,
	[fldKargar2] [nvarchar](20) NULL,
	[fldKargar3] [nvarchar](20) NULL,
	[fldKargar4] [nvarchar](20) NULL,
	[fldKargar5] [nvarchar](20) NULL,
	[fldMarkazHazine] [nvarchar](50) NULL,
	[fldShomareParvande] [nvarchar](20) NULL,
	[fldGhesteVam] [nvarchar](20) NULL,
	[fldSayereBimeHa] [nvarchar](20) NULL,
	[fldTedadRoozeNobat] [nvarchar](20) NULL,
	[fldVam1] [nvarchar](20) NULL,
	[fldVam2] [nvarchar](20) NULL,
	[fldVam3] [nvarchar](20) NULL,
	[fldSVam1] [nvarchar](20) NULL,
	[fldSVam2] [nvarchar](20) NULL,
	[fldSVam3] [nvarchar](20) NULL,
	[fldMazayayeBedooneMaliat] [nvarchar](10) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblGharardad]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblGharardad](
	[fldCodePersonel] [nvarchar](20) NULL,
	[fldKarkard] [nvarchar](8) NULL,
	[fldEzafeKar] [nvarchar](8) NULL,
	[fldTatilKar] [nvarchar](8) NULL,
	[fldJomeKar] [nvarchar](8) NULL,
	[fldKasreKar] [nvarchar](8) NULL,
	[fldEstehghaghi] [nvarchar](8) NULL,
	[fldEstelaji] [nvarchar](8) NULL,
	[fldGheibat] [nvarchar](8) NULL,
	[fldBedooneHoghoogh] [nvarchar](8) NULL,
	[fldShift] [nvarchar](7) NULL,
	[fldAyameMamooriat] [nvarchar](8) NULL,
	[fldHagheMamooriat] [nvarchar](20) NULL,
	[fldAlalHesab] [nvarchar](20) NULL,
	[fldPadash] [nvarchar](20) NULL,
	[fldSayereMotalebat] [nvarchar](20) NULL,
	[fldMosaede] [nvarchar](20) NULL,
	[fldSahmeSandoogh] [nvarchar](20) NULL,
	[fldMah] [nvarchar](2) NULL,
	[fldBimeSahmeKargar] [nvarchar](20) NULL,
	[fldMaliateHoghoogh] [nvarchar](20) NULL,
	[fldKasrekarKol] [nvarchar](20) NULL,
	[fldJameHoghooghVaMazaya] [nvarchar](20) NULL,
	[fldKhalesePardakhti] [nvarchar](20) NULL,
	[fldDastmozdeMahane] [nvarchar](20) NULL,
	[fldEzafeKari] [nvarchar](20) NULL,
	[fldTatilKari] [nvarchar](20) NULL,
	[fldNobatKari] [nvarchar](20) NULL,
	[fldJomeKari] [nvarchar](20) NULL,
	[fld1] [nvarchar](20) NULL,
	[fld2] [nvarchar](20) NULL,
	[fld3] [nvarchar](20) NULL,
	[fld4] [nvarchar](20) NULL,
	[fld5] [nvarchar](20) NULL,
	[fld6] [nvarchar](20) NULL,
	[fld7] [nvarchar](20) NULL,
	[fld8] [nvarchar](20) NULL,
	[fld9] [nvarchar](20) NULL,
	[fld10] [nvarchar](20) NULL,
	[fld11] [nvarchar](20) NULL,
	[fld12] [nvarchar](20) NULL,
	[fld13] [nvarchar](20) NULL,
	[fld14] [nvarchar](20) NULL,
	[fld15] [nvarchar](20) NULL,
	[fld16] [nvarchar](20) NULL,
	[fld17] [nvarchar](20) NULL,
	[fldName] [nvarchar](30) NULL,
	[fldFamily] [nvarchar](40) NULL,
	[fldShomareShenasname] [nvarchar](15) NULL,
	[fldMashmooleBime] [nvarchar](20) NULL,
	[fldSayereKosoor] [nvarchar](20) NULL,
	[fldMashmooleMaliat] [nvarchar](20) NULL,
	[fldShomareBime] [nvarchar](12) NULL,
	[fldShoghl] [nvarchar](30) NULL,
	[fldNamePedar] [nvarchar](30) NULL,
	[fldDateEstekhdam] [nvarchar](10) NULL,
	[fldDateTark] [nvarchar](10) NULL,
	[fldShomareHesab] [nvarchar](30) NULL,
	[fldCodeKargah] [nvarchar](15) NULL,
	[fldKargar1] [nvarchar](20) NULL,
	[fldKargar2] [nvarchar](20) NULL,
	[fldKargar3] [nvarchar](20) NULL,
	[fldKargar4] [nvarchar](20) NULL,
	[fldKargar5] [nvarchar](20) NULL,
	[fldMarkazHazine] [nvarchar](50) NULL,
	[fldShomareParvande] [nvarchar](20) NULL,
	[fldGhesteVam] [nvarchar](20) NULL,
	[fldNameVaFamily] [nvarchar](140) NULL,
	[fldFather] [nvarchar](50) NULL,
	[fldDateTavalod] [nvarchar](10) NULL,
	[fldCodeMeli] [nvarchar](13) NULL,
	[fldMahaleSodoor] [nvarchar](50) NULL,
	[fldDateStart] [nvarchar](10) NULL,
	[fldDateEnd] [nvarchar](10) NULL,
	[fldMozoo] [nvarchar](50) NULL,
	[fldS1] [nvarchar](50) NULL,
	[fldS2] [nvarchar](50) NULL,
	[fldS3] [nvarchar](50) NULL,
	[fldS4] [nvarchar](50) NULL,
	[fldS5] [nvarchar](50) NULL,
	[fldS6] [nvarchar](50) NULL,
	[fldS7] [nvarchar](50) NULL,
	[fldS8] [nvarchar](50) NULL,
	[fldS9] [nvarchar](50) NULL,
	[fldS10] [nvarchar](50) NULL,
	[fldS11] [nvarchar](50) NULL,
	[fldS12] [nvarchar](50) NULL,
	[fldS13] [nvarchar](50) NULL,
	[fldS14] [nvarchar](50) NULL,
	[fldS15] [nvarchar](50) NULL,
	[fldS16] [nvarchar](50) NULL,
	[fldS17] [nvarchar](50) NULL,
	[fldDastmozd] [nvarchar](20) NULL,
	[fldMahal] [nvarchar](50) NULL,
	[fldVahed] [nvarchar](50) NULL,
	[fldModat] [nvarchar](50) NULL,
	[fldMolahezat] [nvarchar](50) NULL,
	[fldAdress] [nvarchar](250) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblGhestevam]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblGhestevam](
	[fldRadif] [nvarchar](20) NULL,
	[fldMaheGhest] [nvarchar](2) NULL,
	[fldSaleGhest] [nvarchar](2) NULL,
	[fldShomareGhest] [nvarchar](3) NULL,
	[fldMablagh] [nvarchar](25) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblInformation]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblInformation](
	[fldEsfand] [nvarchar](3) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblJadvaleMaliati]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblJadvaleMaliati](
	[fldRadif] [nvarchar](3) NULL,
	[fldHoghoogh] [nvarchar](20) NULL,
	[fldDarsad] [nvarchar](5) NULL,
	[fldMah] [nvarchar](5) NULL,
	[fldLock] [nvarchar](1) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblKarbar]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblKarbar](
	[fldName] [nvarchar](20) NULL,
	[fldPass] [nvarchar](20) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblKarkardeMahane]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblKarkardeMahane](
	[fldCodePersonel] [nvarchar](20) NULL,
	[fldKarkard] [nvarchar](8) NULL,
	[fldEzafeKar] [nvarchar](8) NULL,
	[fldTatilKar] [nvarchar](8) NULL,
	[fldJomeKar] [nvarchar](8) NULL,
	[fldKasreKar] [nvarchar](8) NULL,
	[fldEstehghaghi] [nvarchar](8) NULL,
	[fldEstelaji] [nvarchar](8) NULL,
	[fldGheibat] [nvarchar](8) NULL,
	[fldBedooneHoghoogh] [nvarchar](8) NULL,
	[fldShift] [nvarchar](8) NULL,
	[fldAyameMamooriat] [nvarchar](8) NULL,
	[fldHagheMamooriat] [nvarchar](20) NULL,
	[fldAlalHesab] [nvarchar](20) NULL,
	[fldPadash] [nvarchar](20) NULL,
	[fldSayereMotalebat] [nvarchar](20) NULL,
	[fldMosaede] [nvarchar](20) NULL,
	[fldSahmeSandoogh] [nvarchar](20) NULL,
	[fldMah] [nvarchar](2) NULL,
	[fldBimeSahmeKargar] [nvarchar](20) NULL,
	[fldMaliateHoghoogh] [nvarchar](20) NULL,
	[fldKasrekarKol] [nvarchar](20) NULL,
	[fldJameHoghooghVaMazaya] [nvarchar](20) NULL,
	[fldKhalesePardakhti] [nvarchar](20) NULL,
	[fldDastmozdeMahane] [nvarchar](20) NULL,
	[fldEzafeKari] [nvarchar](20) NULL,
	[fldTatilKari] [nvarchar](20) NULL,
	[fldNobatKari] [nvarchar](20) NULL,
	[fldJomeKari] [nvarchar](20) NULL,
	[fldLock] [nvarchar](1) NULL,
	[fldGhesteVam] [nvarchar](20) NULL,
	[fldTedadRoozeNobat] [nvarchar](20) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblKolMoin]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblKolMoin](
	[fldCodeHesab] [nvarchar](50) NULL,
	[fldSharheHesab] [nvarchar](100) NULL,
	[fldNoeHesab] [nvarchar](15) NULL,
	[fldCodeNoeHesab] [nvarchar](5) NULL,
	[fldMarkazFirst] [nvarchar](10) NULL,
	[fldMarkazSecond] [nvarchar](10) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblMarkaz1]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMarkaz1](
	[fldCode] [nvarchar](10) NULL,
	[fldSharh] [nvarchar](100) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblMarkaz2]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMarkaz2](
	[fldCode] [nvarchar](10) NULL,
	[fldSharh] [nvarchar](100) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblMarkazehazine]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMarkazehazine](
	[fldRadif] [nvarchar](5) NULL,
	[fldCode] [nvarchar](50) NULL,
	[fldSharh] [nvarchar](100) NULL,
	[fldKol] [nvarchar](10) NULL,
	[fldMoin] [nvarchar](10) NULL,
	[fldTafzili] [nvarchar](10) NULL,
	[fldMarkaz1] [nvarchar](10) NULL,
	[fldMarkaz2] [nvarchar](10) NULL,
	[fldCodeNoeTafzili] [nvarchar](5) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblMashaghel]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMashaghel](
	[fldCode] [nvarchar](7) NULL,
	[fldSharh] [nvarchar](40) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblMazayayeSabeteHoghooghi]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMazayayeSabeteHoghooghi](
	[fldSharh] [nvarchar](50) NULL,
	[fldMaliat] [nvarchar](2) NULL,
	[fldBime] [nvarchar](2) NULL,
	[fldMabna] [nvarchar](2) NULL,
	[fldRadif] [nvarchar](5) NULL,
	[fldMah] [nvarchar](2) NULL,
	[fldLock] [nvarchar](1) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblMoarefieBankha]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMoarefieBankha](
	[fldNameBank] [nvarchar](100) NULL,
	[fldNameShobe] [nvarchar](100) NULL,
	[fldCodeShobe] [nvarchar](20) NULL,
	[fldShomareHesab] [nvarchar](50) NULL,
	[fldRadif] [nvarchar](5) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblMoarefieKargah]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMoarefieKargah](
	[fldRadif] [nvarchar](5) NULL,
	[fldCodeKargah] [nvarchar](15) NULL,
	[fldNameKargah] [nvarchar](60) NULL,
	[fldNameKarfarma] [nvarchar](60) NULL,
	[fldShobe] [nvarchar](50) NULL,
	[fldAdress] [nvarchar](100) NULL,
	[fldMah] [nvarchar](2) NULL,
	[fldLock] [nvarchar](1) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblMoarefiePersonel]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMoarefiePersonel](
	[fldRadif] [nvarchar](5) NULL,
	[fldCodePersonel] [nvarchar](20) NULL,
	[fldName] [nvarchar](30) NULL,
	[fldFamily] [nvarchar](40) NULL,
	[fldNamePedar] [nvarchar](30) NULL,
	[fldShomareShenasname] [nvarchar](15) NULL,
	[fldShomareMeli] [nvarchar](15) NULL,
	[fldMahaleSodoor] [nvarchar](20) NULL,
	[fldMahaleTavalod] [nvarchar](20) NULL,
	[fldDateTavalod] [nvarchar](10) NULL,
	[fldDateEstekhdam] [nvarchar](10) NULL,
	[fldMadrak] [nvarchar](10) NULL,
	[fldShoghl] [nvarchar](30) NULL,
	[fldShomarePosteSazmani] [nvarchar](15) NULL,
	[fldCodeMashaghel] [nvarchar](15) NULL,
	[fldGorooh] [nvarchar](15) NULL,
	[fldTaahol] [nvarchar](2) NULL,
	[fldNoeEstekhdam] [nvarchar](5) NULL,
	[fldVaziatePersonel] [nvarchar](5) NULL,
	[fldOzveHeiateModire] [nvarchar](5) NULL,
	[fldShomareBime] [nvarchar](15) NULL,
	[fldCodeKargahi] [nvarchar](15) NULL,
	[fldCodeMarkazhazine] [nvarchar](15) NULL,
	[fldShomareHesab] [nvarchar](30) NULL,
	[fldNoeHesab] [nvarchar](5) NULL,
	[fldCodebank] [nvarchar](20) NULL,
	[fldSarmayeSandoogh] [nvarchar](30) NULL,
	[fldDateTark] [nvarchar](50) NULL,
	[fldMah] [nvarchar](2) NULL,
	[fldLock] [nvarchar](1) NULL,
	[fldLockCode] [nvarchar](1) NULL,
	[fldCodePosti] [nvarchar](10) NULL,
	[fldSex] [nvarchar](1) NULL,
	[fldShomareParvande] [nvarchar](5) NULL,
	[fldMoarefiBedaraei] [nvarchar](3) NULL,
	[fldNoeBime] [nvarchar](3) NULL,
	[fldMahaleKhedmat] [nvarchar](15) NULL,
	[fldVaziateMahaleKhedmat] [nvarchar](3) NULL,
	[fldNoeGharardad] [nvarchar](3) NULL,
	[fldVaziateKarmand] [nvarchar](5) NULL,
	[fldBimeEzafekar] [nvarchar](5) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblMoshakhasatePardakhtKonande]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblMoshakhasatePardakhtKonande](
	[fldNameSherkat] [nvarchar](50) NULL,
	[fldCodeEghtesadi] [nvarchar](12) NULL,
	[fldAdress] [nvarchar](150) NULL,
	[fldCodePosti] [nvarchar](50) NULL,
	[fldTel] [nvarchar](20) NULL,
	[fldNameShobe] [nvarchar](30) NULL,
	[fldTFN] [nvarchar](12) NULL,
	[fldCodeShobe] [nvarchar](2) NULL,
	[fldName1] [nvarchar](15) NULL,
	[fldFamily1] [nvarchar](50) NULL,
	[fldSemat1] [nvarchar](30) NULL,
	[fldShomareMelli1] [nvarchar](10) NULL,
	[fldName2] [nvarchar](15) NULL,
	[fldFamily2] [nvarchar](50) NULL,
	[fldSemat2] [nvarchar](30) NULL,
	[fldShomareMelli2] [nvarchar](50) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblPaye]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblPaye](
	[fldKol] [nvarchar](50) NULL,
	[fldMoin] [nvarchar](50) NULL,
	[fldTafzili] [nvarchar](50) NULL,
	[fldMarkaz1] [nvarchar](50) NULL,
	[fldMarkaz2] [nvarchar](50) NULL,
	[fldMaheSaleMali] [nvarchar](50) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblReportSanavat]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblReportSanavat](
	[fldCodePersenel] [nvarchar](20) NULL,
	[fldName] [nvarchar](90) NULL,
	[fldFamily] [nvarchar](90) NULL,
	[fldSanavateGozashte] [nvarchar](5) NULL,
	[fldKarkardeJari] [nvarchar](8) NULL,
	[fldDastMozdeRoozane] [nvarchar](20) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblSabteEtelaateSabeteHoghooghi]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSabteEtelaateSabeteHoghooghi](
	[fldRadifeTblMazayayeSabeteHoghooghi] [nvarchar](5) NULL,
	[fldCodePersonel] [nvarchar](20) NULL,
	[fldMablagh] [nvarchar](20) NULL,
	[fldDastMozdeMahane] [nvarchar](20) NULL,
	[fldMah] [nvarchar](2) NULL,
	[fldLock] [nvarchar](1) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblSabteEtelaateSayereBimeha]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSabteEtelaateSayereBimeha](
	[fldCodePersonel] [nvarchar](20) NULL,
	[fldKargar1] [nvarchar](20) NULL,
	[fldKargar2] [nvarchar](20) NULL,
	[fldKargar3] [nvarchar](20) NULL,
	[fldKargar4] [nvarchar](20) NULL,
	[fldKargar5] [nvarchar](20) NULL,
	[fldKarfarma1] [nvarchar](20) NULL,
	[fldKarfarma2] [nvarchar](20) NULL,
	[fldKarfarma3] [nvarchar](20) NULL,
	[fldKarfarma4] [nvarchar](20) NULL,
	[fldKarfarma5] [nvarchar](20) NULL,
	[fldMah] [nvarchar](2) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblSabteVamhaVaSayereKosoor]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSabteVamhaVaSayereKosoor](
	[fldCodePersonel] [nvarchar](20) NULL,
	[fldCodeVame] [nvarchar](20) NULL,
	[fldMizaneVam] [nvarchar](20) NULL,
	[fldMizaneGhest] [nvarchar](70) NULL,
	[fldTedad] [nvarchar](20) NULL,
	[fldMaheShoroo] [nvarchar](20) NULL,
	[fldSaleShoroo] [nvarchar](20) NULL,
	[fldRadif] [nvarchar](20) NULL,
	[fldMah] [nvarchar](2) NULL,
	[fldLock] [nvarchar](1) NULL,
	[fldMandeVam] [nvarchar](20) NULL,
	[fldGhesteMaheJari] [nvarchar](50) NULL,
	[fldMah1] [nvarchar](10) NULL,
	[fldMah2] [nvarchar](10) NULL,
	[fldMah3] [nvarchar](10) NULL,
	[fldMah4] [nvarchar](10) NULL,
	[fldMah5] [nvarchar](10) NULL,
	[fldMah6] [nvarchar](10) NULL,
	[fldMah7] [nvarchar](10) NULL,
	[fldMah8] [nvarchar](10) NULL,
	[fldMah9] [nvarchar](10) NULL,
	[fldMah10] [nvarchar](10) NULL,
	[fldMah11] [nvarchar](10) NULL,
	[fldMah12] [nvarchar](10) NULL,
	[fldMahNemoone1] [nvarchar](10) NULL,
	[fldMahNemoone2] [nvarchar](10) NULL,
	[fldMahNemoone3] [nvarchar](10) NULL,
	[fldMahNemoone4] [nvarchar](10) NULL,
	[fldMahNemoone5] [nvarchar](10) NULL,
	[fldMahNemoone6] [nvarchar](10) NULL,
	[fldMahNemoone7] [nvarchar](10) NULL,
	[fldMahNemoone8] [nvarchar](10) NULL,
	[fldMahNemoone9] [nvarchar](10) NULL,
	[fldMahNemoone10] [nvarchar](10) NULL,
	[fldMahNemoone11] [nvarchar](10) NULL,
	[fldMahNemoone12] [nvarchar](10) NULL,
	[fldMahNemoone13] [nvarchar](10) NULL,
	[fldMahNemoone14] [nvarchar](10) NULL,
	[fldMahNemoone15] [nvarchar](10) NULL,
	[fldMahNemoone16] [nvarchar](10) NULL,
	[fldMahNemoone17] [nvarchar](10) NULL,
	[fldMahNemoone18] [nvarchar](10) NULL,
	[fldMahNemoone19] [nvarchar](10) NULL,
	[fldMahNemoone20] [nvarchar](10) NULL,
	[fldMahNemoone21] [nvarchar](10) NULL,
	[fldMahNemoone22] [nvarchar](10) NULL,
	[fldMahNemoone23] [nvarchar](10) NULL,
	[fldMahNemoone24] [nvarchar](10) NULL,
	[fldMahNemoone25] [nvarchar](10) NULL,
	[fldMahNemoone26] [nvarchar](10) NULL,
	[fldMahNemoone27] [nvarchar](10) NULL,
	[fldMahNemoone28] [nvarchar](10) NULL,
	[fldMahNemoone29] [nvarchar](10) NULL,
	[fldMahNemoone30] [nvarchar](10) NULL,
	[fldMahNemoone31] [nvarchar](10) NULL,
	[fldMahNemoone32] [nvarchar](10) NULL,
	[fldMahNemoone33] [nvarchar](10) NULL,
	[fldMahNemoone34] [nvarchar](10) NULL,
	[fldMahNemoone35] [nvarchar](10) NULL,
	[fldMahNemoone36] [nvarchar](10) NULL,
	[fldMahNemoone37] [nvarchar](10) NULL,
	[fldMahNemoone38] [nvarchar](10) NULL,
	[fldMahNemoone39] [nvarchar](10) NULL,
	[fldMahNemoone40] [nvarchar](10) NULL,
	[fldMahNemoone41] [nvarchar](10) NULL,
	[fldMahNemoone42] [nvarchar](10) NULL,
	[fldMahNemoone43] [nvarchar](10) NULL,
	[fldMahNemoone44] [nvarchar](10) NULL,
	[fldMahNemoone45] [nvarchar](10) NULL,
	[fldMahNemoone46] [nvarchar](10) NULL,
	[fldMahNemoone47] [nvarchar](10) NULL,
	[fldMahNemoone48] [nvarchar](10) NULL,
	[fldMahNemoone49] [nvarchar](10) NULL,
	[fldMahNemoone50] [nvarchar](10) NULL,
	[fldMahNemoone51] [nvarchar](10) NULL,
	[fldMahNemoone52] [nvarchar](10) NULL,
	[fldMahNemoone53] [nvarchar](10) NULL,
	[fldMahNemoone54] [nvarchar](10) NULL,
	[fldMahNemoone55] [nvarchar](10) NULL,
	[fldMahNemoone56] [nvarchar](10) NULL,
	[fldMahNemoone57] [nvarchar](10) NULL,
	[fldMahNemoone58] [nvarchar](10) NULL,
	[fldMahNemoone59] [nvarchar](10) NULL,
	[fldMahNemoone60] [nvarchar](10) NULL,
	[fldMahNemoone61] [nvarchar](10) NULL,
	[fldMahNemoone62] [nvarchar](10) NULL,
	[fldMahNemoone63] [nvarchar](10) NULL,
	[fldMahNemoone64] [nvarchar](10) NULL,
	[fldMahNemoone65] [nvarchar](10) NULL,
	[fldMahNemoone66] [nvarchar](10) NULL,
	[fldMahNemoone67] [nvarchar](10) NULL,
	[fldMahNemoone68] [nvarchar](10) NULL,
	[fldMahNemoone69] [nvarchar](10) NULL,
	[fldMahNemoone70] [nvarchar](10) NULL,
	[fldMahNemoone71] [nvarchar](10) NULL,
	[fldMahNemoone72] [nvarchar](10) NULL,
	[fldMahNemoone73] [nvarchar](10) NULL,
	[fldMahNemoone74] [nvarchar](10) NULL,
	[fldMahNemoone75] [nvarchar](10) NULL,
	[fldMahNemoone76] [nvarchar](10) NULL,
	[fldMahNemoone77] [nvarchar](10) NULL,
	[fldMahNemoone78] [nvarchar](10) NULL,
	[fldMahNemoone79] [nvarchar](10) NULL,
	[fldMahNemoone80] [nvarchar](10) NULL,
	[fldMahNemoone81] [nvarchar](10) NULL,
	[fldMahNemoone82] [nvarchar](10) NULL,
	[fldMahNemoone83] [nvarchar](10) NULL,
	[fldMahNemoone84] [nvarchar](10) NULL,
	[fldMahNemoone85] [nvarchar](10) NULL,
	[fldMahNemoone86] [nvarchar](10) NULL,
	[fldMahNemoone87] [nvarchar](10) NULL,
	[fldMahNemoone88] [nvarchar](10) NULL,
	[fldMahNemoone89] [nvarchar](10) NULL,
	[fldMahNemoone90] [nvarchar](10) NULL,
	[fldMahNemoone91] [nvarchar](10) NULL,
	[fldMahNemoone92] [nvarchar](10) NULL,
	[fldMahNemoone93] [nvarchar](10) NULL,
	[fldMahNemoone94] [nvarchar](10) NULL,
	[fldMahNemoone95] [nvarchar](10) NULL,
	[fldMahNemoone96] [nvarchar](10) NULL,
	[fldMahNemoone97] [nvarchar](10) NULL,
	[fldMahNemoone98] [nvarchar](10) NULL,
	[fldMahNemoone99] [nvarchar](10) NULL,
	[fldAghsatePardakhtShodeSaleGhabl] [nvarchar](10) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblSanavat]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSanavat](
	[fldCodePersonel] [nvarchar](20) NULL,
	[fldSanavateGozashte] [nvarchar](4) NULL,
	[fldFarvardin] [nvarchar](10) NULL,
	[fldOrdibehesht] [nvarchar](10) NULL,
	[fldKhordad] [nvarchar](10) NULL,
	[fldTir] [nvarchar](10) NULL,
	[fldMordad] [nvarchar](10) NULL,
	[fldShahrivar] [nvarchar](10) NULL,
	[fldMehr] [nvarchar](10) NULL,
	[fldAban] [nvarchar](10) NULL,
	[fldAzar] [nvarchar](10) NULL,
	[fldDey] [nvarchar](10) NULL,
	[fldBahman] [nvarchar](10) NULL,
	[fldEsfand] [nvarchar](10) NULL,
	[fldMorakhasi] [nvarchar](5) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblSarfasleVam]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSarfasleVam](
	[fldRadif] [nvarchar](5) NULL,
	[fldCode] [nvarchar](3) NULL,
	[fldSharh] [nvarchar](99) NULL,
	[fldNoe] [nvarchar](5) NULL,
	[fldSanadMali] [nvarchar](12) NULL,
	[fldLock] [nvarchar](1) NULL,
	[fldMah] [nvarchar](2) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblSayereBimeha]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSayereBimeha](
	[fldSharh] [nvarchar](100) NULL,
	[fldKargar] [nvarchar](10) NULL,
	[fldNerkheKargar] [nvarchar](10) NULL,
	[fldKarfarMa] [nvarchar](10) NULL,
	[fldNerkheKarfarma] [nvarchar](10) NULL,
	[fldRadif] [int] NULL,
	[fldMah] [nvarchar](2) NULL,
	[fldLock] [nvarchar](1) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblSodooreSanad]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblSodooreSanad](
	[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,
	[fldCodeMarkazHazine] [nvarchar](50) NULL,
	[fldSanad] [nvarchar](10) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblTafzili]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblTafzili](
	[fldNoeHesab] [nvarchar](15) NULL,
	[fldSharheTafzili] [nchar](100) NULL,
	[fldCodeTafzili] [nvarchar](50) NULL,
	[fldCodeNoe] [nvarchar](50) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblZarayebeSabeteHoghooghi]    Script Date: 11/13/2023 9:22:34 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblZarayebeSabeteHoghooghi](
	[fldSaghfeBimeRoozane] [nvarchar](20) NULL,
	[fldSaghfeEidi] [nvarchar](20) NULL,
	[fldMah] [nvarchar](2) NULL,
	[fldEsfand] [nvarchar](2) NULL,
	[fldLock] [nvarchar](1) NULL,
	[fldKafeHoghoogheRoozane] [nvarchar](20) NULL
) ON [PRIMARY]
GO



delete tblCityIran
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1000000, N'استان تهران', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1001000, N'تهران', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1001103, N'زرقان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1001104, N'دولاب', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1001105, N'کوي  سيزدهم  ابان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1001200, N'کن', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1001201, N'سولقان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1001902, N'گلندوک', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1002000, N'اسلامشهر', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1002101, N'ده  عباس', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1002102, N'صالح  اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1002200, N'چهاردانگه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1002201, N'فيروزبهرام', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003000, N'دماوند', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003101, N'رودهن', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003102, N'کيلان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003103, N'تارورد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003104, N'مرا', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003105, N'ابعلي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003106, N'جمع  ابرود', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003108, N'ابرشيوه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003109, N'سربندان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003200, N'فيروزکوه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003201, N'حبلرود', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003202, N'اتشان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003203, N'پشتکوه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003204, N'سرانزا', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003205, N'شهراباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003206, N'قزقانچي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003207, N'ارجمند', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003208, N'وزنا', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003209, N'انزها', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003901, N'جاجرود', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003902, N'جابان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003903, N'سياهرود', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003904, N'گل  گنگک', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003905, N'زور', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003906, N'مشاع', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003907, N'دوره', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003908, N'دشت مزار', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003909, N'ميگون', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003910, N'گندم  اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1003911, N'حرانک', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004000, N'شهر ري', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004100, N'مرکزي  ري', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004101, N'خلازير', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004102, N'غني  اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004200, N'فشاپويه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004201, N'حسن آباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004202, N'وهن اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004300, N'کهريزک', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004301, N'باقرشهر', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004302, N'قلعه  نو', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004901, N'حکيم  اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004902, N'بهشت زهرا', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004903, N'اسمعيل  اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004904, N'قصطانک', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004905, N'منصوراباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004906, N'علي  ابادراه  قم', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004907, N'نعمت اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1004908, N'ولي  ابادنو', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006000, N'شميرانات', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006101, N'تجريش', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006200, N'لواسانات', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006204, N'افجه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006300, N'رودبارقصران', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006301, N'فشم', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006302, N'حاجي آباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006903, N'زرگنده', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006904, N'رستم  اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006905, N'کندسفلي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006906, N'دزاشيب', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006907, N'درکه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006908, N'داراباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006909, N'کامرانيه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006910, N'کاشانک', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006911, N'قنات کوثر', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006912, N'قلهک', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006913, N'امامه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006914, N'اقدسيه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006915, N'تلخ  اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006917, N'اوشان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1006918, N'مراتع  لار', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007000, N'شهريار', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007100, N'مرکزي  شهريار', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007101, N'قدس', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007102, N'اکبراباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007103, N'ملارد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007104, N'وحيديه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007105, N'ابسرد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007106, N'اختراباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007107, N'بي  بي  سکينه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007109, N'جوقين', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007110, N'رزکان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007111, N'فردوس', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007112, N'قايم  اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007113, N'مويز', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007114, N'ده  مويز', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007115, N'سعيداباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007200, N'رباطکريم', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007202, N'امام  زاده  ابوطالب', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007203, N'ادران', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007204, N'منجيل  اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007300, N'شهر قدس', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007400, N'بهارستان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007901, N'چهاردانگه  شهرياري', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007902, N'کهنه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007903, N'ده  شاه  بالا', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007904, N'کرشته', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1007905, N'علي  بيات', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010000, N'ورامين', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010100, N'مرکزي  ورامين', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010101, N'قرچک', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010102, N'بهنام  پازوکي  جنوبي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010103, N'باقرآباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010104, N'بهنام  وسطي  شمالي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010105, N'باغ  خواص', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010106, N'بومهن', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010200, N'پاکدشت', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010201, N'بهنام  پازوکي  شمالي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010202, N'حصارامير', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010203, N'بهنام  سوخته  شمالي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010204, N'کريم  اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010205, N'فيلستان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010206, N'تجن', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010300, N'جواداباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010301, N'بهنام غرب جنوبي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010302, N'بهنام وسطي جنوبي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010303, N'آب باريک', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010400, N'پيشوا', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010401, N'عسگريه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010402, N'عسگرابادعباسي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010403, N'بهنام  سوخته  جنوبي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010404, N'جليل  اباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010905, N'شمس ابادعرب', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010906, N'کهنه  گل', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010907, N'زواره  بيد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010908, N'دمزاباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010909, N'دربالا', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010910, N'داوداباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010911, N'نجف ابادباقرين', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010912, N'کاظم  ابادوسط', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010913, N'قلعه  نوتپه  سرجان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010914, N'قلعه  سين', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010915, N'خيرابادخالصه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010916, N'حاجي  ابادسالار', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010917, N'حصارحسن بيک', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010918, N'حصارقاضي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010919, N'بوالعرز', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010920, N'خاتون آباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010921, N'خالداباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010922, N'چالتاسيان', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010923, N'يوسف ابادخالصه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010925, N'چرم  شهر', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010926, N'مامازند', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010927, N'پارچين', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1010928, N'خيراباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1099901, N'ارنگه', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1099902, N'جعفرآباد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1099903, N'اکراد', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1099904, N'فرحناز', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1099905, N'غارغربي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1099906, N'غارشرقي', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1099907, N'عليشاه  عوض', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1099908, N'سرخه  حصار', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1099909, N'پردیس', N'تهران', 10)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1200000, N'استان مازندران', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201000, N'ساري', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201100, N'مرکزي  ساري', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201101, N'اسفيورشوراب', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201102, N'شرفدارکلاه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201103, N'رودپي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201104, N'اکند', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201105, N'کليجان رستاق  سفلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201106, N'سنگتراشان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201107, N'کليجان رستاق  عليا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201108, N'پايين هولار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201109, N'مياندورودکوچک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201110, N'سه  سکنده  عليا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201111, N'مذکوره', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201112, N'بندارخيل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201200, N'چهاردانگه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201201, N'کياسر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201202, N'پشتکوه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201203, N'تلمادره', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201204, N'گرماب', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201205, N'خالخيل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201300, N'دودانگه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201301, N'بنافت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201302, N'سنگده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201303, N'فريم', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201304, N'محمدآباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201305, N'وزملا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201306, N'سياهدشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201400, N'مياندرود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201401, N'مياندرودبزرگ', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201402, N'اسلام آباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201403, N'کوهدشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201404, N'سورک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201901, N'وليک بن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201903, N'پنبه  چوله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201904, N'بالارسکت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201905, N'بالاکوه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201906, N'برا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201907, N'ورند', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201908, N'کياده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201909, N'سودکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201911, N'ميانرود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201912, N'مازارستاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201913, N'لنگر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201914, N'گلورد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201915, N'صفراباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1201917, N'ترم', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202000, N'امل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202100, N'مرکزي  امل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202101, N'بالاخيابان ليتکوه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202102, N'اسکومحله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202103, N'پايين خيابان ليتکوه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202104, N'مرانده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202105, N'چلاو', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202106, N'رزکه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202107, N'دشت سر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202108, N'نجارمحله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202109, N'دابوي  جنوبي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202110, N'رييس اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202111, N'هرازپي  جنوبي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202112, N'قادي  محله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202200, N'لاريجان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202201, N'رينه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202202, N'بالالاريجان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202203, N'گزنک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202204, N'لاريجان سفلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202205, N'بايجان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202901, N'موزيرج', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202902, N'نوگردن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202903, N'شرمه  کلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202904, N'شاهکني', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202905, N'شاکرمحله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202906, N'کهن پا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202907, N'سنگ درکا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202909, N'زوارک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202910, N'رودباردشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202911, N'دورانسرسفلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202912, N'ورسکي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202913, N'نسل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202914, N'کرف', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202915, N'مارکتي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202916, N'لتي  کلهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202917, N'لاسم', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202918, N'منگوده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202919, N'گزانه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202920, N'عاليکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202921, N'چنگاز', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202922, N'خوشرود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202925, N'پاشاکلاعليا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1202926, N'بامرکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203000, N'بابل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203100, N'مرکزي  بابل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203101, N'اميرکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203102, N'بابل  کنار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203103, N'مرزيکلاه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203104, N'فيضيه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203105, N'سلطان محمدطاهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203106, N'گنج  افروز', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203107, N'پايين گنج  افروز', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203108, N'گتاب', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203109, N'پايين گتاب', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203110, N'کاري  پي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203111, N'زرگرمحله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203112, N'لاله  اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203113, N'پايين احمدچاله  پي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203200, N'بندپي  شرقي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203201, N'سجادرود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203203, N'فيروزجاه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203204, N'فيروزجاه  ثابت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203300, N'بندپي  غربي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203301, N'خوش رود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203302, N'خوش رودپي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203303, N'شهيداباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203304, N'شياده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203901, N'امين خان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203902, N'انديکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203903, N'اهنگرکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203904, N'بيشه  سر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203905, N'شيردارکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203906, N'چلياسر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203907, N'سنگ چال', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203908, N'روشن اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203909, N'نشل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203910, N'متي  کلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203911, N'کبرياکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203912, N'قميکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203913, N'علمدار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1203914, N'گرميچ', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204000, N'بابلسر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204100, N'مرکزي  بابلسر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204101, N'بابلرود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204102, N'بابل  پشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204103, N'ساحلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204104, N'باقرتنگه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204200, N'رودبست', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204201, N'خشکرود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204202, N'پازوار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204203, N'ايسي  کلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204300, N'بهنمير', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204301, N'عزيزک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204400, N'فريدونکنار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204401, N'امام  زاده  عبدالله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204402, N'کارکردمحله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204403, N'باريک رود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204404, N'فيروزاباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1204901, N'سقري  کلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205000, N'بهشهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205100, N'مرکزي  بهشهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205101, N'رستمکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205102, N'کوهستان -  مرکزي  بهشهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205103, N'ميان کاله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205104, N'زاغمرز', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205200, N'گلوگاه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205201, N'پنج  هزاره', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205202, N'علمدارمحله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205203, N'کلباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205204, N'لمراسک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205300, N'يانه  سر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205301, N'شهدا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205302, N'سفيدچاه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205303, N'عشرستاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1205304, N'بيشه  بنه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206000, N'محمودآباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206100, N'مرکزي  محموداباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206101, N'اهلمرستاق  شمالي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206102, N'ازادمون', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206103, N'اهلمرستاق  جنوبي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206104, N'کلوده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206105, N'هرازپي  غربي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206106, N'خطاهن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206200, N'سرخرود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206201, N'دابوي  شمالي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206202, N'هرازپي  شمالي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206203, N'بيشه  کلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1206901, N'ميناکلمرز', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207000, N'ترکمن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207100, N'مرکزي  ترکمن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207101, N'بندرترکمن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207102, N'جعفرباي  جنوبي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207103, N'سيجوال', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207200, N'گميشان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207201, N'گميش تپه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207202, N'جعفرباي  شرقي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207203, N'بناور', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207204, N'جعفرباي  غربي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207205, N'خواجه  نفس', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1207901, N'قرنجيک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208000, N'تنکابن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208100, N'مرکزي  تنکابن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208101, N'خرم آباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208103, N'قلعه  گردن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208104, N'گليجان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208105, N'سليمان اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208106, N'دوهزار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208107, N'امامزاده  قاسم', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208108, N'سه  هزار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208109, N'يوج', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208200, N'عباس اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208201, N'سلمان شهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208202, N'نشتارود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208203, N'کلاراباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208204, N'کلار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208205, N'تازه  اباد -  عباس اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208206, N'لنگارود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208208, N'کترا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208901, N'مرودشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208902, N'لاتراشان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1208903, N'گلعلي  اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1209000, N'رامسر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1209100, N'مرکزي  رامسر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1209101, N'کتالم  وسادات محله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1209102, N'جهل  شهيد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1209103, N'گالش محله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1209104, N'سخت سر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1209105, N'جنت رودبار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1209106, N'اشکورتنکابن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1209107, N'تمل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1209901, N'کردمحله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210000, N'سوادکوه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210100, N'مرکزي  سوادکوه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210101, N'پل  سفيد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210102, N'الاشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210103, N'زيراب', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210104, N'سرخکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210105, N'راستوپي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210106, N'شورمست پي  رودبار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210107, N'ولوپي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210108, N'لله  بند', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210109, N'کسليان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210110, N'اتو', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210200, N'شيرگاه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210201, N'شرق  وغرب شيرگاه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210202, N'کليج  خيل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210203, N'لفور', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210204, N'شارقلت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210901, N'ورسک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210902, N'بورخاني', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210903, N'خرمنديچال', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210904, N'ازانده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210905, N'جديداسلام', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210906, N'رجه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210907, N'دهميان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210908, N'شيرمست', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1210909, N'اردستان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1211000, N'علي آباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1211100, N'مرکزي  علي  اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1211101, N'استراباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1211102, N'فاضل  اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1211103, N'کتول', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1211104, N'مزرعه -  مرکزي  علي  اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1211901, N'معصوم  اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212000, N'قايم  شهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212100, N'مرکزي  قايم  شهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212101, N'کياکلا -  مرکزي  قايم  شهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212103, N'قاديکلاارطه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212104, N'بالاتجن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212105, N'شيخ  علي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212106, N'تالارپي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212107, N'سنگتاب', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212109, N'قاديکلابزرگ', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212110, N'نوکندکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212111, N'رکابدارکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212112, N'سوخت ابندان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212200, N'جويبار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212201, N'کياکلا -  جويبار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212202, N'نجارکلاجديد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212203, N'سياهرود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212204, N'گليرد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212205, N'گيل  خواران', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212206, N'کوهي  خيل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212207, N'استانه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212208, N'درازمحله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212901, N'دنج  کلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212902, N'کرتنا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212903, N'هتکهکوه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212904, N'گوني  باني', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212905, N'وديکلابورطه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212906, N'گرمابه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212907, N'خطيرکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212908, N'درکاس', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212909, N'چمازکتي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1212910, N'سيدمحله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213000, N'کردکوي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213100, N'مرکزي  کردکوي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213101, N'چهارکوه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213102, N'سرکلاته', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213103, N'سدن رستاق  شرقي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213104, N'يساقي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213105, N'سدن رستاق  غربي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213106, N'چهارده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213200, N'بندرگز', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213201, N'نوکنده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213202, N'انزان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1213203, N'گزغربي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214000, N'گرگان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214100, N'مرکزي  گرگان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214101, N'استرابادجنوبي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214102, N'جلين عليا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214103, N'استرابادشمالي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214104, N'سرخنکلاته', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214105, N'انجيراب', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214106, N'رنگيان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214108, N'لمسک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214109, N'سرخ  پشته', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214110, N'نوده  ملک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214200, N'اق  قلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214201, N'اق  التين', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214202, N'عطااباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214203, N'شيخ  موسي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214204, N'گري  دوجي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214205, N'گرگان بوي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214206, N'قنقرمه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214207, N'مزرعه -  اق  قلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214208, N'انبارالوم', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214901, N'کفشگيري', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214902, N'الوکلاته', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1214903, N'دازشقال  تپه  سفلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215000, N'گنبدکاووس', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215100, N'مرکزي  گنبدکاووس', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215101, N'اق  اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215102, N'باغلي  ماراما', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215103, N'فجر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215104, N'سلطانعلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215200, N'ازادشهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215201, N'چشمه  ساران', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215202, N'فارسيان -  ازادشهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215203, N'خرمارود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215204, N'نوده  خاندوز', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215205, N'نظام  اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215206, N'قشلاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215207, N'زيتونلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215300, N'داشلي  برون', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215301, N'اترک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215303, N'کرند', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215400, N'راميان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215401, N'خان ببين', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215402, N'دلند', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215403, N'فندرسک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215404, N'دارکلاته', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215405, N'قلعه  ميران', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215406, N'باقرآباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215901, N'بلخان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215902, N'الهادي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215903, N'دانشمند', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215904, N'امام  زاده  يحيي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215905, N'اميرمحمدقلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215906, N'بهکله  بابل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215907, N'ايشک تپه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215908, N'ايگورعليا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215909, N'پشمک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215910, N'تنگلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215911, N'چات', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215912, N'چاي  قوشن يستطيج', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215913, N'ميوه  چي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215914, N'يکه  چنار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215915, N'کوچک قان نميز', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215916, N'ده  ضياشک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215917, N'لکيجه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215918, N'قوريلجه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215919, N'قره  محمدتپه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1215920, N'گدايجه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216000, N'مينودشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216100, N'مرکزي  مينودشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216101, N'چهل  چاي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216102, N'الفجر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216103, N'قلعه  قافه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216104, N'کوهسارات', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216105, N'دوزين', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216200, N'کلاله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216201, N'اق  سو', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216202, N'اجن سنگرلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216203, N'تمران', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216204, N'تمرقره  قوزي  سفلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216205, N'زاوکوه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216206, N'پيشکمر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216207, N'کنگور', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216208, N'اچي  لک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216300, N'گاليکش', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216301, N'قراولان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216302, N'اق  قميش', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216303, N'نيلکوه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216304, N'فارسيان -  گاليکش', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216305, N'ينقاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216400, N'مراوه  تپه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216401, N'گلي  داغ', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216402, N'يازگلدي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216901, N'تازه  کشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1216902, N'لوه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217000, N'نور', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217100, N'مرکزي  نور', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217101, N'رويان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217102, N'ميان بند', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217103, N'گاسيگرمحله', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217104, N'ناتل  کنارسفلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217105, N'ايزده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217106, N'ناتل  کنارعليا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217107, N'سلياکتي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217200, N'بلده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217201, N'اوزرود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217202, N'پيل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217203, N'تتارستاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217204, N'تاکر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217205, N'شيخ  فضل  الله  نوري', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217300, N'چمستان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217301, N'ناتل  رستاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217303, N'بنفشه  ده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217304, N'لاويج', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217305, N'رييس کلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217306, N'گرناسرا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217901, N'علمده', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217902, N'رستم  رود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217904, N'کمر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217906, N'نسن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217907, N'بردون', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1217908, N'شهرکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218000, N'نوشهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218100, N'مرکزي  نوشهر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218101, N'بلده  کجور', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218102, N'اندرود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218103, N'خيرودکنار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218104, N'موسي  اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218105, N'کالج', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218106, N'نارنج  بن', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218200, N'کلاردشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218201, N'مرزن اباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218202, N'کرديچال', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218203, N'کوهستان -  کلاردشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218204, N'طوير', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218205, N'بيرون بشم', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218206, N'گويتر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218207, N'گرکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218208, N'پيشاسه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218300, N'کجور', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218301, N'پنجک رستاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218302, N'دشت نظير', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218303, N'توابع  کجور', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218304, N'زانوس رستاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218305, N'پول', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218400, N'چالوس', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218401, N'کلاررستاق  غربي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218402, N'هچي  رود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218403, N'کلارستاق  شرقي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218404, N'تازه  اباد -  چالوس', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1218901, N'ساس', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219000, N'نکا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219100, N'مرکزي  نکا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219101, N'مهروان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219102, N'گل  خيل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219103, N'قره  طغان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219104, N'طوسکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219105, N'پي  رجه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219106, N'زرندين سفلي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219200, N'هزارجريب', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219201, N'زارم  رود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219202, N'زيارت کلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219203, N'استخرپشت', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219901, N'تازه  ابادکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219902, N'چالمردي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1219903, N'اهراب', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299901, N'شهرخواست', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299902, N'ناييچ', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299903, N'سوچلما', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299904, N'کوه  پر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299905, N'کوکلان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299906, N'ميانرودعليا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299907, N'ساقي  کلايه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299908, N'ساسي  کلام', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299909, N'زواره', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299911, N'رينملاريجان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299912, N'رودبار', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299913, N'رمدانخيل', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299914, N'رستاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299915, N'کمررود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299916, N'دلارستاج', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299917, N'کليجان ييلاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299918, N'کلررودپي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299919, N'وازيک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299920, N'کجرستاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299921, N'نمارستاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299922, N'نرماب دوسر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299923, N'قجق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299924, N'ملک', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299925, N'قان يخمزشرقي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299926, N'قانچي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299927, N'گلباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299928, N'علويکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299929, N'مغريکا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299930, N'هلوپشته', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299931, N'يخکش', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299932, N'چهاردانگه  سورتجي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299933, N'چهاردانگه  هزارجريبي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299934, N'بندرج', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299935, N'حسن کيف', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299936, N'اميري', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299937, N'حومه  کران', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299938, N'بهرستان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299939, N'خانقاه  پي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299940, N'اوزرودعليا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299941, N'پالرود', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299942, N'پلور', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299943, N'اينچه  برون', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299944, N'ايندواجان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299945, N'استرابادرستاق', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299946, N'اتاباي  جنوبي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299947, N'اتاباي  شمالي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299948, N'تيرستان', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299949, N'جعفرياي  شمالي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299950, N'جلال  ارزک جنوبي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299951, N'جلال  ارزک شمالي', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299952, N'چلندر', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299953, N'خيراباد', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299954, N'اق  قلعه', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299955, N'بانصرکلا', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1299956, N'هراز', N'مازندران', 12)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1300000, N'استان اذربايجان شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301000, N'تبريز', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301100, N'مرکزي  تبريز', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301101, N'باسمنج', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301102, N'سردرود', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301103, N'اجي  چاي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301104, N'مايان سفلي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301105, N'اسپران', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301106, N'ينگي  اسپران', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301107, N'جزيره', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301108, N'سراي  ده', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301109, N'سردصحرا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301110, N'خلجان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301111, N'ميدانچاي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301112, N'کندرود -  مرکزي  تبريز', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301113, N'اولي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301200, N'اذرشهر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301201, N'گاوکان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301202, N'ممقان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301203, N'شيرامين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301204, N'قاضي  جهان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301205, N'قبله  داغي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301206, N'ناديلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301207, N'تيمورلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301208, N'المالوداش', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301300, N'اسکو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301301, N'خسروشهر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301302, N'ايلخچي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301303, N'باويل', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301304, N'کله  جاه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301305, N'شورگات جنوبي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301306, N'خاص اباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301307, N'شورگات شمالي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301308, N'لاهيجان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301309, N'گنبر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301310, N'اربط', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301311, N'سهند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301312, N'اسفنجان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301313, N'اق  گنبد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301314, N'سرين ديزج', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301901, N'مشيراباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301902, N'بلويردي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1301904, N'بارنج', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302000, N'اهر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302100, N'مرکزي  اهر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302101, N'اذغان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302102, N'اوچ  هاچا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302103, N'يخفروزان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302104, N'بزکش', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302105, N'گرنگاه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302106, N'قشلاق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302107, N'تازه  کند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302108, N'گويچه  بل', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302109, N'خونيق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302110, N'ورگهان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302200, N'خروانق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302201, N'ارزيل', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302202, N'جوشين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302203, N'ديزمارمرکزي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302300, N'ورزقان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302301, N'ازومدل  جنوبي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302302, N'ازومدل  شمالي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302303, N'تخمدل', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302304, N'بکراباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302305, N'سينا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302306, N'اقابابافرامرزي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302400, N'هوراند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302401, N'چهاردانگه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302402, N'اق  براز', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302403, N'دودانگه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302404, N'ديکله', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302405, N'مجيداباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302901, N'سرکش', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302902, N'زنداباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302903, N'کنک ل  اباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302904, N'ديزج  چراغ', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302905, N'کلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302906, N'قراقيه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302907, N'گندوقدي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302908, N'فروردين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302909, N'علي  بيک کندي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302910, N'عليار', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302911, N'طرزم', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302912, N'شيخدار', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302913, N'ارضين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302914, N'اوانه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302915, N'ايت کندي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302916, N'بزه  جان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1302917, N'بجوشين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303000, N'سراب', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303100, N'مرکزي  سراب', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303101, N'ابرغان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303102, N'اغميون', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303103, N'حومه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303104, N'اسب فروشان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303105, N'رازليق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303106, N'صايين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303107, N'کليان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303108, N'ملايعقوب', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303109, N'اردها', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303200, N'مهربان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303201, N'اردلان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303202, N'اسنق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303203, N'الان براغوش', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303204, N'الان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303205, N'شربيان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303901, N'شاللو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303902, N'سلطان اباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303903, N'سرين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303904, N'زيراسف', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303905, N'کاديجان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303906, N'قوشچي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303907, N'قلعه  جوق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303908, N'قره  مسجد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303909, N'هروان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303910, N'صومعه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303911, N'بلالجين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303913, N'دوزدوزان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303914, N'اندراب', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303915, N'داراب', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303916, N'اسفنان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303917, N'تيره  جين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303918, N'بالستان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1303919, N'براغوش', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304000, N'مراغه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304100, N'مرکزي  مراغه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304101, N'سراجوي  شمالي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304102, N'داش اتان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304103, N'قره  ناز', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304104, N'ورجوي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304105, N'سراجوي  غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304106, N'علويان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304200, N'سراجو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304201, N'سراجوي  شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304202, N'خراجو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304203, N'قوري  چاي  غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304204, N'داشبلاغ  بازار', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304205, N'سراجوي  جنوبي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304206, N'گل  تپه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304300, N'عجب شير', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304301, N'ديزجرودغربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304302, N'شيشوان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304303, N'ديزجرودشرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304304, N'جوان قلعه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304305, N'چوبانکر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1304306, N'مهراباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305000, N'مرند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305100, N'مرکزي  مرند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305102, N'زنوز', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305103, N'دولت آباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305104, N'کشکسراي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305105, N'هرزندات غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305106, N'گلين قيه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305107, N'زنوزق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305108, N'ميشاب شمالي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305109, N'کندلج', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305110, N'هرزندات شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305111, N'هرزندجديد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305200, N'يامچي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305201, N'ذوالبين -  يامچي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305202, N'يکانات', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305203, N'يکان کهريز', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305901, N'بهرام', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305902, N'اينانلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305903, N'بالقوزاغاج', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305904, N'ميزاب', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305905, N'کيان عليا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305906, N'کوهناب', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305907, N'سگبان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305908, N'سعدي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305909, N'زنجيره', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305910, N'زم', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305911, N'يکان عليا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305912, N'کندعب', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305913, N'ديزه  جيکان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305914, N'ديزج  قربان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305916, N'يام', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1305917, N'مغولو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1306000, N'جلفا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1306100, N'مرکزي  جلفا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1306101, N'ارسي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1306102, N'هاديشهر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1306103, N'شجاع', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1306200, N'سيه  رود', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1306201, N'ديزمارغربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1306202, N'نوجه  مهر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1306203, N'داران', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1306901, N'سيه  سران', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1306902, N'ليوارجان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307000, N'ميانه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307100, N'مرکزي  ميانه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307101, N'اوج  تپه  شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307102, N'پورسخلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307103, N'شيخ  دراباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307104, N'قافلانکوه  غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307105, N'اچاچي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307106, N'قزل  اوزن', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307107, N'قويوجاق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307108, N'کله  بوزشرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307109, N'کنگاور', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307110, N'کله  بوزغربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307111, N'باشماق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307112, N'گرمه  جنوبي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307113, N'گوندوغدي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307200, N'ترکمانچاي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307201, N'اوج  تپه  غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307202, N'خاتون آباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307203, N'براونان شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307204, N'صومعه  عليا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307205, N'براونان غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307206, N'قريب دوست', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307207, N'براونان مرکزي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307208, N'ورنکش', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307300, N'کاغذکنان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307301, N'قافلانکوشرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307302, N'چلاقلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307303, N'کاغذکنان شمالي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307304, N'قره  بلاغ', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307305, N'کاغذکنان مرکزي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307306, N'اقکند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307400, N'کندوان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307401, N'تيرچايي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307402, N'ايشاق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307403, N'ترک', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307404, N'گرمه  شمالي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307405, N'ارموداق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307901, N'بلندتيمور', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307902, N'اميرآباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307903, N'خانيوردي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307904, N'اوج  تپه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307905, N'شاه  علي  بيگلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307906, N'دويچ', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307907, N'قوچقار', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1307908, N'طاوسلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308000, N'هشترود', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308100, N'مرکزي  هشترود', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308101, N'چاراويماق  شمالشرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308102, N'نصيراباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308103, N'سلوک', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308104, N'علي آباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308105, N'قرانقو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308106, N'ذوالبين -  مرکزي  هشترود', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308107, N'کوهسار', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308108, N'اوشندل', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308109, N'باغچه  جق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308200, N'چاراويماق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308201, N'قره  اغاج', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308202, N'چاراويماغ  مرکزي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308203, N'چاراويماغ  جنوب غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308204, N'ارسکناي  سفلي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308205, N'چاراويماق  جنوب شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308206, N'ذاکرکندي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308207, N'چاراويماق  شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308208, N'اغچه  ريش', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308209, N'ورقه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308211, N'کلب کندي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308212, N'عربشاه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308300, N'نظرکهريزي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308301, N'المالو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308302, N'اتش بيک', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308303, N'قوري  چاي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308304, N'اغ  زيارت', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308901, N'اغچه  مشهد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308902, N'خورجستان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308903, N'چراغچي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308904, N'سعادتلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308905, N'مدلوچراغمردان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308907, N'دين اوغلي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308908, N'ظهرابند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1308909, N'نخوداباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309000, N'بناب', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309100, N'مرکزي  بناب', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309101, N'بناجوي  شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309102, N'خوشه  مهر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309103, N'بناجوي  شمالي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309104, N'روشت بزرگ', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309105, N'بناجوي  غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309106, N'خانه  برق  جديد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309901, N'جلقايي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309902, N'تازه  قلعه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309903, N'تازه  کندخان کندي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1309904, N'شيخ  بابا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310000, N'ملکان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310100, N'مرکزي  ملکان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310101, N'گاودول  شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310102, N'اق  منار', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310103, N'گاودول  غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310104, N'بايقوت', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310105, N'گاودول  مرکزي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310106, N'اروق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310200, N'ليلان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310201, N'ليلان جنوبي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310202, N'ليلان شمالي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310203, N'طوراغاجي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1310910, N'باباکلک', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311000, N'بستان اباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311100, N'مرکزي  بستان اباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311101, N'اوجان غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311102, N'بنه  کهل', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311103, N'شبلي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311104, N'سعيداباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311105, N'مهرانرودجنوبي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311106, N'حاج  اقا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311107, N'مهرانرودمرکزي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311108, N'کردکندي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311109, N'قوريگل', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311110, N'يوسف اباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311111, N'حاجي  عبدال', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311200, N'تيکمه  داش', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311201, N'سهنداباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311202, N'قره  چاي  حاج  علي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311203, N'اوجان شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311204, N'قره  بابا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311205, N'عباس شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311206, N'قره  چمن', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311207, N'عباس غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311901, N'قاشقايي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311902, N'کله  خان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311903, N'کلتان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311904, N'قره  حسين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311905, N'گلهين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311906, N'گلوج', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311907, N'عين الدين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311908, N'چيني  بلاغ', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311909, N'پيرلوجه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311910, N'دبلکوه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311911, N'اشتلق  عليا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311912, N'بستان ابادسفلي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1311913, N'ساروخليل', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312000, N'شبستر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312100, N'مرکزي  شبستر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312101, N'سيس', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312102, N'شنداباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312103, N'گوني  مرکزي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312104, N'کوزه  کنان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312105, N'گوني  شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312106, N'بنيس', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312107, N'شرفخانه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312108, N'وايقان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312109, N'خامنه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312200, N'انزاب', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312201, N'تسوج', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312202, N'گوني  غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312203, N'تيل', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312204, N'چهرگان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312300, N'صوفيان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312301, N'چله  خانه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312302, N'چله  خانه  عليا', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312303, N'رودقات', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312304, N'امند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312305, N'ميشوجنوبي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312306, N'نعمت اله', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312307, N'کندرود -  صوفيان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312901, N'شانجان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312902, N'نوجه  ده', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312903, N'ديزج  شيخ  مربان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312904, N'کافي  الملک', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312905, N'عليشاه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312906, N'انده  بيل', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312907, N'بينس', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312908, N'دازيان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312909, N'ابنيس', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312910, N'توپچي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1312911, N'تويچي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313000, N'کليبر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313100, N'مرکزي  کليبر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313101, N'ابش احمد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313102, N'پيغان چايي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313103, N'يوزبند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313104, N'مولان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313105, N'ميشه  پاره', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313107, N'بيلاق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313108, N'عربشاه  خان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313200, N'خداافرين', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313201, N'بسطاملو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313202, N'ديزمارشرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313203, N'مردانقم', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313204, N'کيوان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313205, N'خمارلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313206, N'منجوان شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313207, N'جانانلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313208, N'منجوان غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313209, N'عاشقلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313210, N'گرمادوز', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313211, N'لاريجان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313901, N'گوار', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313902, N'اش احمدلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313903, N'احمدلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1313905, N'خالان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314000, N'هريس', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314100, N'مرکزي  هريس', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314101, N'خانه  رود', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314102, N'انديس', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314103, N'زرنق', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314104, N'بخشايش', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314105, N'مهرانرودشمالي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314106, N'بدوستان شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314107, N'مقصودلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314200, N'خواجه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314201, N'مواضع  خان شرقي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314202, N'مواضع  خان شمالي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314203, N'سرند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314204, N'بدوستان غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314205, N'بيلوردي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314901, N'کيوج', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314902, N'رجل  اباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314903, N'خانقاه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314904, N'دبکلو', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314905, N'تازه  کندسرند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1314906, N'جهان اباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399901, N'دريامان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399902, N'حسن آباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399903, N'قاسم  اباد', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399904, N'خانمرود', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399905, N'غربي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399906, N'اجارود', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399907, N'بروانان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399908, N'برزند', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399909, N'ينگجه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399910, N'قوريچلي', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399911, N'علمدار', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399912, N'گرمه', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399913, N'مغان', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399914, N'گرگر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399915, N'طسوج', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399916, N'کچلرات', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399917, N'انگوت', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399918, N'گله  چار', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399919, N'اطراف شهر', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1399920, N'سرخه  ريز', N'آذربايجان شرقي', 13)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1400000, N'استان اذربايجان غربي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401000, N'اروميه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401100, N'مرکزي  اروميه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401101, N'باراندوزچاي  حنوبي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401102, N'بالانج', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401103, N'باراندوزچاي  شمالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401104, N'قره  اغاج -  مرکزي  اروميه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401105, N'باش قلعه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401106, N'يورقون اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401107, N'باراندوز', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401108, N'بکشلوچاي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401109, N'امامزاده', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401110, N'ترکمان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401111, N'دول', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401112, N'ديزج  دول', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401113, N'روضه  چاي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401114, N'بالو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401115, N'نازلوي  جنوبي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401116, N'چنقرالوي  يکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401200, N'نازلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401201, N'نوشين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401202, N'طلاتپه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401203, N'نازلوچاي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401204, N'نازلوشمالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401300, N'انزل', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401301, N'قوشچي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401302, N'انزل  جنوبي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401303, N'قولنجي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401304, N'انزل  شمالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401305, N'قره  باغ -  انزل', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401400, N'سيلوانه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401401, N'ترگور', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401402, N'موانا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401403, N'مرگور', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401404, N'زيوه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401405, N'دشت', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401406, N'راژان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401407, N'ابني', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401409, N'کوجار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401410, N'نوي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401411, N'قصريک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401412, N'گسيان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401413, N'شيخ  شمزين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401414, N'هارويان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401500, N'صوماي  برادوست', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401501, N'برادوست', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401502, N'روندسفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401503, N'صوماي  حنوبي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401504, N'هشتيان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401505, N'صوماي  شمالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401506, N'ممکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401701, N'بتستان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401702, N'دربند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401703, N'جلقران', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401704, N'جله  قوش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401705, N'جمال  اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401706, N'براسب', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401707, N'اقاصلوي  عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401708, N'اغقال', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401709, N'اقدين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401710, N'اخيان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401711, N'چره', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401712, N'الواج', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401713, N'کوسه  احمد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401714, N'شکفتيک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401715, N'حيدرلوي  بيکلر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401716, N'گنگچين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401801, N'تيزخراب', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401802, N'گوجار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401803, N'قرابقلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401804, N'قدني', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401805, N'قاطرچي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401806, N'قاسملو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401807, N'گنبد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401809, N'گله  خر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401810, N'فقي  پيکر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401811, N'گلشيخان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401812, N'فرککلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401813, N'گلدانکو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401814, N'مکين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401815, N'گلپاشين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401816, N'غفارجي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401817, N'عيباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401819, N'عمراباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401820, N'علي  کومي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401821, N'علي  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401822, N'علي  بيگلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401823, N'گزنق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401824, N'عسگرابادتپه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401825, N'گرماير', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401826, N'گرگ تپه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401827, N'طرزيلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401829, N'صورمان اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401830, N'گچه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401831, N'گجين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401832, N'شيرکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401833, N'يلقون اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401834, N'چوبتراش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401835, N'چونقرالوي  پل', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401836, N'بلول  اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401837, N'دويره', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401838, N'ارزين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401839, N'حاجي  پيرلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401840, N'ديران حسيني', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401841, N'حسين آباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401842, N'حصار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401843, N'دولاها', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401844, N'حصارداغ  باني', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401845, N'بوربور', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401846, N'ديزج', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401847, N'حلج', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401848, N'ديزج  اقاعلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401849, N'حله  قوش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401850, N'حماملارد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401851, N'داش اغول', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401852, N'ارصالو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401853, N'بويين يوغونلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401854, N'دارغلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401855, N'حي  ملار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401856, N'به  لبو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401857, N'خالداباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401858, N'خانقاه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401859, N'خانقاه  سرخ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401860, N'اباجلوسفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401861, N'اوانسر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401862, N'خليان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401863, N'خرگوش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401864, N'خرم آباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401866, N'خضراباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401867, N'بي  صنعر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401868, N'اوصالو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401869, N'اسنگران', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401870, N'ايران حسيني', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401871, N'پسان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401872, N'ايکدير', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401873, N'پورقانلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401874, N'پيرمراد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401875, N'اشنااباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401877, N'تازه  کندقاطرچي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401878, N'باران', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401879, N'تالين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401880, N'باشلابنوشلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401881, N'تکالو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401882, N'اسکندراباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401884, N'شمس حاجيان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401885, N'توپوزاباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401886, N'بافي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401887, N'تولکي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401888, N'تولي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401889, N'تويوزاباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401890, N'ملونه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401891, N'جارچلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401892, N'بالولان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401893, N'جاريحان سفلا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401894, N'اغسقال', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401895, N'جانوسيلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401896, N'باوان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401897, N'جبل', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401898, N'جرمني', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401899, N'افتابه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401901, N'سراسکند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401902, N'ميراباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401903, N'شفلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401904, N'مياوق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401905, N'سين اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401906, N'هنگروان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401907, N'کهريز', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401908, N'سيدان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401909, N'سيد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401910, N'سيارک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401911, N'سولک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401912, N'سنگران', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401913, N'سنجي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401914, N'سنجري', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401915, N'سمکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401916, N'سليم  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401917, N'سلوانق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401918, N'هفتسار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401919, N'سکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401920, N'نيچالان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401921, N'همکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401922, N'سرگرگان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401923, N'کولق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401924, N'کوکيا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401925, N'نرگي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401926, N'ستکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401927, N'سليم  بيک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401928, N'ساديجلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401929, N'زيرمانلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401930, N'مرانه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401931, N'کوره  عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401932, N'زنکلان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401933, N'کورجين قلعه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401934, N'کورانه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401935, N'کودان اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401936, N'زرگ اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401937, N'کوچين قلعه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401938, N'زاراباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401939, N'کوتالان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401940, N'جوهني', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401941, N'ريک اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401942, N'کواسب', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401943, N'روندعليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401944, N'روزعليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401945, N'محمودآباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401946, N'رشکه  سو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401947, N'کندوک ملا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401948, N'هاشم  اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401949, N'کمقان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401950, N'کليسا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401952, N'کله  فر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401953, N'نجف اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401954, N'کريم  اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401955, N'رحيم آباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401956, N'کرلق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401957, N'کردلر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401958, N'نوپراق  قلعه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401959, N'يونس اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401960, N'ريشکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401971, N'کبريزجديلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401972, N'کايزان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401973, N'کاني  قوزان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401974, N'کانرش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401975, N'لورزيني', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401976, N'لور', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401977, N'کافرش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401978, N'کازش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401979, N'لنجي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401980, N'لک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401981, N'قوني', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401982, N'قوزيونه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401983, N'قوزان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401984, N'منگول', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401985, N'قليلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401986, N'قلقاچي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401987, N'يرده  کش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401988, N'قرالرگورخانه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401989, N'ميرداود', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401990, N'گيچه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401991, N'قلعه  اسماعيل  اقا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401992, N'قلعه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401993, N'قصه  يک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401994, N'قشلاق  محمدشريف', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401995, N'گوگلتي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401996, N'گوگجه  ياران', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401997, N'گورچين قلعه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401998, N'قرنسا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1401999, N'قراله', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402000, N'بوکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402100, N'سيمينه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402101, N'بهي  دهبکري', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402102, N'جوانمرد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402103, N'اختاچي  شرقي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402104, N'داشبند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402105, N'اختاچي  محالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402106, N'قره  موسالو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402200, N'مرکزي  بوکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402201, N'ايل  گورک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402202, N'گلولان سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402203, N'ايل  تيمور', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402204, N'نوبار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402205, N'اختاچي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402206, N'قره  کند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402207, N'بهي  فيض اله  بيگي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402208, N'يکشوه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402901, N'قاطانقور', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1402902, N'علي آباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403000, N'پيرانشهر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403100, N'مرکزي  پيرانشهر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403101, N'پيران', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403103, N'منگورغربي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403104, N'کوير', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403105, N'لاهيجان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403106, N'دريکه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403200, N'لاجان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403201, N'لاهيجان شرقي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403202, N'پسوه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403203, N'لاهيجان غربي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403204, N'سيلوه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1403901, N'جلديان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404000, N'تکاب', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404100, N'مرکزي  تکاب', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404101, N'انصار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404102, N'دورباش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404103, N'افشار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404104, N'ارغول  بيک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404105, N'کرفتو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404106, N'قوجه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404200, N'تخت سليمان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404201, N'احمد آباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404202, N'احمدابادسفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404203, N'چمن', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404204, N'قره  بلاغ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404205, N'ساروق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404206, N'چوپلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404901, N'گاورون', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404902, N'شليلوند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404903, N'سنوکش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404904, N'ليلان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404905, N'قيه  بلاغ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404906, N'صفانجق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404907, N'تازه  کندعلي  اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1404908, N'باروق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405000, N'خوي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405100, N'مرکزي  خوي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405101, N'فيرورق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405102, N'الند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405103, N'بله  سورسفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405104, N'ايواوغلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405106, N'رهال', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405107, N'قوروق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405108, N'سکمن اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405109, N'زوراباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405110, N'يسک سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405111, N'قطور', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405112, N'ولديان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405113, N'سعيداباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405114, N'قره  سو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405115, N'ديزج  ديز', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405200, N'چايپاره', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405201, N'قره  ضياالدين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405202, N'چورس', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405203, N'حاجيلار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405204, N'بسطام', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405205, N'اسماعيل  کهريز', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405206, N'اغمزار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405207, N'چرکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405209, N'سالطه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405210, N'مارکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405901, N'حاشيه  رود', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405902, N'حبش عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405903, N'حمزيان سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405904, N'بيلوار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405905, N'دنبلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405906, N'پيرکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405907, N'بدل  اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405908, N'اقاميري  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405909, N'چشمه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405910, N'اقبلاغ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405912, N'شوراب', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405913, N'سيدتاج  الدين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405914, N'ياربم  قيه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405915, N'سکتلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405916, N'زارعان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405917, N'وار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405918, N'هندوان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405919, N'نوايي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405920, N'نيگجه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405921, N'کابت', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405922, N'قيردرق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405923, N'قزلداغ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405924, N'قريس', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405925, N'قره  قوش سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1405926, N'ملاجند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406000, N'سردشت', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406100, N'مرکزي  سردشت', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406101, N'الان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406102, N'اسلام آباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406103, N'باسک کولسه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406104, N'بريسو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406105, N'برياجي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406106, N'بيوران سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406107, N'گورک سردشت', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406108, N'ربط', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406200, N'وزينه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406201, N'گورک نطين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406203, N'ملکاري', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406204, N'نلاس', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406901, N'دودکان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406902, N'کولسه  عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1406903, N'نيوکردار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407000, N'سلماس', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407100, N'مرکزي  سلماس', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407101, N'تازه  شهر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407102, N'چهريق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407103, N'زولاچاي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407104, N'ملحم', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407105, N'شپيران', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407106, N'دلزي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407107, N'شناتال', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407108, N'کوزه  رش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407109, N'کره  سني', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407110, N'سيلاب', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407111, N'کنارپروژ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407112, N'تمر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407113, N'لکستان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407114, N'قره  قشلاق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407901, N'سرتق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407902, N'هرکيان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407903, N'کوچمشک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407904, N'ميرشانلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407905, N'ماته  قريه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407906, N'کانيان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407907, N'نظراباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407908, N'گولان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407909, N'قزلجه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407910, N'قذراباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407911, N'صوفي  اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407912, N'صدقيان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407913, N'مغانجوق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407914, N'چهرگان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407915, N'ارلق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407916, N'خان تختي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407918, N'خسرواباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407919, N'اولق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407920, N'تازه  کند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407921, N'برازي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407922, N'بروشقالان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407923, N'درشک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1407924, N'بزبزان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408000, N'شاهين دژ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408100, N'مرکزي  شاهين دژ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408101, N'هولاسو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408102, N'صفاخانه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408103, N'محمودآباد -  مرکزي  شاهين دژ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408200, N'کشاورز', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408201, N'عشاور', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408202, N'چهاردولي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408203, N'صورين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408204, N'اجرلوي  شرقي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408205, N'نختالو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408206, N'اجرلوي  غربي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408207, N'قره  قچي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408208, N'اجرلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408901, N'شورجه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408902, N'محمودجق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408903, N'زمان اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408904, N'جان اقا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408905, N'چچکلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1408906, N'باغ  عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409000, N'مهاباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409100, N'مرکزي  مهاباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409101, N'اختاچي  غربي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409102, N'قره  باغ -  مرکزي  مهاباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409103, N'مکريان شرقي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409104, N'گوگ تپه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409105, N'مکريان غربي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409106, N'درياز', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409200, N'خليفان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409201, N'کاني  بازار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409202, N'کيتکه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409203, N'منگورشرقي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409204, N'عبدالله  کرده', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409901, N'قياغلندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1409902, N'اسماعيل  کند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410000, N'ماکو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410100, N'مرکزي  ماکو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410101, N'بازرگان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410102, N'چايپاسارشمالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410103, N'قوش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410104, N'چايپاسارجنوبي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410105, N'قره  تپه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410106, N'قلعه  دره  سي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410107, N'کشمش تپه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410200, N'پلدشت', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410201, N'چايپاسارشرقي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410202, N'عشق  اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410203, N'زنگبار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410204, N'بهلول  اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410205, N'گچلرات غربي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410206, N'نازک عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410207, N'گچلرات شرقي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410208, N'بيگ خان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410209, N'ميرزاکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410300, N'سيه  چشمه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410301, N'چالدران شمالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410302, N'زاويه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410303, N'چالدران جنوبي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410304, N'خضرلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410305, N'اواجيق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410306, N'کليساکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410307, N'ببه  جيک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410308, N'قرنقو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410309, N'ارخشان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410310, N'داردره  سي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410311, N'حراملو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410312, N'امامقلي  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410313, N'انجه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410314, N'خان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410315, N'دکلساويردي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410316, N'بيانچوي  عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410317, N'بيگ کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410318, N'پاييزاباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410319, N'اينجه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410320, N'دوشان تپه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410321, N'اينجه  سليم', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410322, N'اينچه  صلاح  سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410323, N'اينچه  صلاح  عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410324, N'مزرعه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410325, N'قيانکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410326, N'قره  جه  ورن', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410327, N'گل  اشاقه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410328, N'بارون', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410329, N'پيراحمد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410330, N'بابالو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410331, N'تخت روان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410332, N'تخت روان سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410333, N'تغنت عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410334, N'تفت سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410335, N'اغبلاغ  خالد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410336, N'تولکي  تپه  سر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410337, N'جبارعليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410338, N'جگن', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410339, N'جليل  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410340, N'جمال  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410341, N'چاوش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410342, N'معصوم  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410343, N'ناور', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410344, N'شاه  بندلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410345, N'شارلوسفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410346, N'علي آباد -  سيه  چشمه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410347, N'سيران', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410348, N'سگريک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410349, N'سعدن', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410350, N'نبي  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410351, N'قيزخاچلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410352, N'قولار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410353, N'قلي  ديزج', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410354, N'گول', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410355, N'قزل  سوري', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410356, N'قزلداش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410357, N'قره  اغل', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410358, N'قرخ  بلاغ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410359, N'قراغل', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410360, N'قدوکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410361, N'قاشق  بلاغ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410362, N'عيسي  گولي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410363, N'عموخانزه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410364, N'شيخ  سيلوي  سفلا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410366, N'عباسکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410367, N'طهماسب کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410368, N'شيخ  سيلوي  عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410369, N'زاويه  سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410400, N'شوط', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410401, N'قره  قويون شمالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410402, N'صوفي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410403, N'قره  قويون جنوبي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410404, N'مرگن لر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410405, N'يولاگلدي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410406, N'سنق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410717, N'اغبلاغ  چمنلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410801, N'خله  زاغي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410802, N'اغبلاغ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410803, N'درگاهقلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410804, N'تيه  بالشي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410805, N'ذکرلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410806, N'جبارلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410807, N'بايجان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410808, N'جگن سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410809, N'جگن عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410810, N'بدي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410811, N'جنعال', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410812, N'جنون عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410813, N'اقاسري  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410814, N'جوشري', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410815, N'ادرته  کند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410816, N'النلر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410901, N'گاموس', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410902, N'شوريک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410903, N'شوربلاغ  عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410904, N'شوراغل', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410905, N'شاطر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410906, N'شادلوي  سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410907, N'سنگر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410908, N'ساريو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410909, N'هندوار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410910, N'مرادلوي  عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410911, N'زنگنه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410912, N'مخور', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410913, N'مخند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410914, N'هامون بزرگ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410915, N'محموداغلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410916, N'هاسون بزرگ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410917, N'نازک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410918, N'مايل  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410919, N'کندال', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410920, N'کچوي  سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410921, N'ياريم  تيه  سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410922, N'قيرکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410923, N'قونجي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410924, N'قورلوبلاغ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410925, N'قورشاقلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410926, N'قوردالدرن', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410927, N'قوتان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410928, N'قنبرکندي  کرد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410929, N'قنبرکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410930, N'قم', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410931, N'قلمبدنميش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410932, N'کوسنج', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410933, N'قلعه  جوق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410934, N'قزل  داغ  کرد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410935, N'قزل  داغ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410936, N'قزاقشلاق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410937, N'قره  خاج', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410938, N'قره  اياق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410939, N'تکمه  کرد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410940, N'قره  اغاج', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410941, N'قرتان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410943, N'قبانباسان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410944, N'قارقلوق  عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410945, N'قارقلوق  سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410946, N'قارقلوخان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410947, N'فشل  داش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410948, N'فتاح', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410949, N'نظرخان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410950, N'غوطان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410951, N'علي  نظر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410952, N'علي  قندو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410953, N'ملاکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410954, N'علي  فرج', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410955, N'عظيم  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410956, N'عزيزکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410957, N'صوفعلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410958, N'شيطان اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410959, N'شيرمحمد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410960, N'شيخ  سلوعليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410961, N'شيخ  حمزه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410962, N'گجوت', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410963, N'چمنلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410964, N'خله  زاغاسي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410965, N'دانالو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410966, N'امامقلي  کندي  عليا', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410967, N'حسوشکي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410968, N'ديبک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410969, N'دانالوي  بزرگ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410970, N'حوشيري', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410971, N'دم  سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410972, N'دم  قشلاق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410973, N'بهلول  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410974, N'بيانچولي  سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410976, N'اروجکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410977, N'خرمن يري', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410978, N'خلج  کرد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410979, N'اورته  کند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410980, N'اورنلر', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410981, N'پره  خورک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410982, N'رنجه  سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410983, N'رند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410984, N'ايلاتلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410985, N'ايل  قوردويي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410986, N'اينجه  دره  سي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410987, N'پناه  کندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410989, N'پورناک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410990, N'پيراحمدکندي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410991, N'دم', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410993, N'تپه  باشي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410994, N'تپه  سراميک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410995, N'اغ  اتلوق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410996, N'ترکمن', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410997, N'تکمه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410998, N'اينجه  سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1410999, N'باغچه  جوق', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411000, N'مياندواب', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411100, N'مرکزي  مياندواب', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411101, N'زرينه  رودشمالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411102, N'شبيلوي  سفلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411103, N'زرينه  رودجنوبي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411104, N'سرچنار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411106, N'زرينه  رود', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411107, N'بکتاش', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411108, N'مرحمت اباد -  مرکزي  مياندواب', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411109, N'گوگ تپه  خالصه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411110, N'مکريان شمالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411111, N'حاج  حسن', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411200, N'مرحمت اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411201, N'چهاربرج', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411202, N'مرحمت ابادشمالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411203, N'چهاربرج  قديم', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411204, N'مرحمت ابادجنوبي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411205, N'للکلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411901, N'حيدراباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411902, N'نادرگلي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411903, N'گدگ تپه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411904, N'اقکند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411905, N'شاه  تپه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1411906, N'چاخماز', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412000, N'نقده', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412100, N'مرکزي  نقده', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412101, N'محمديار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412102, N'حسنلو', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412103, N'سلدوز', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412104, N'پيراباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412105, N'بيگم  قلعه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412200, N'اشنويه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412201, N'دشت بيل', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412203, N'اشنويه  جنوبي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412204, N'نالوس', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412205, N'اشنويه  شمالي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412206, N'نليوان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412207, N'رشکند', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412208, N'دوستک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412211, N'ترسابلاغ', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412212, N'شوانه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412213, N'سياوان', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412214, N'گندملاعيسي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412215, N'دربه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412216, N'درستک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1412902, N'چيانه', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1499902, N'شهرويران', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1499903, N'سوکمن اباد', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1499904, N'کنگچين', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1499905, N'محديار', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1499906, N'کردبال', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1499907, N'گوي  اغاج', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1499908, N'گورک', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1499909, N'گلاس', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1499910, N'صوملي', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1499911, N'سرکاني', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1499912, N'حاجي  بارام', N'آذربايجان غربي', 14)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1500000, N'استان کرمانشاه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501000, N'کرمانشاه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501100, N'مرکزي  کرمانشاه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501101, N'پشت دربند', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501102, N'مرزباني', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501103, N'ميان دربند', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501104, N'قزانچي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501105, N'قره  سو', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501106, N'کهرارموقوفه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501107, N'دورودفرامان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501108, N'رحيم آباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501109, N'رازاور', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501110, N'قلعه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501111, N'بالادربند', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501112, N'سراب نيلوفر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501113, N'سنجابي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501114, N'کوزران', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501115, N'هفت اشيان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501200, N'فيروزاباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501201, N'سرفيروزاباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501202, N'هلشي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501203, N'جلاوند', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501204, N'چنار', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501205, N'عثمانوند', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501206, N'بوژان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501300, N'ماهيدشت', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501301, N'رباط', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501302, N'چقانرگس', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501901, N'ابطاف', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501902, N'باغني', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501903, N'ده  پير', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501904, N'ذهاب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501905, N'نان زرده', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501906, N'نوراباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501907, N'سراب شاهين', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501908, N'ماهيدشت غربي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501909, N'ورزان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501910, N'هريس', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501911, N'نفت شهر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501912, N'بلشت', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501913, N'اورامان لهون شمالي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1501914, N'اورامان لهون جنوبي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502000, N'اسلام  ابادغرب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502100, N'مرکزي  اسلام  ابادغرب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502101, N'حومه  شمالي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502102, N'برزه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502103, N'حومه  جنوبي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502104, N'مومني', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502105, N'حسن آباد -  مرکزي  اسلام  ابادغرب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502106, N'شيان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502107, N'قلعه  شاهين -  مرکزي  اسلام  ابادغرب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502108, N'ويسکه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502109, N'کرکوي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502200, N'حميل', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502201, N'منصوري', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502202, N'داربيدمنصوري', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502203, N'هرسم', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502204, N'قلعه  هرسم', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502300, N'گهواره', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502301, N'گوراني', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502302, N'قلخاني', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502303, N'زاوله  عليا', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502400, N'کرند', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502401, N'حومه  کرند', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502402, N'طلسم', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502403, N'بان زرده', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502404, N'ريجاب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502405, N'بيوينج', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502406, N'ده  چاهي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502407, N'هوکاني', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502408, N'بيرق  وند', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502409, N'چالادبکري', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502410, N'چشمه  سفيد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502901, N'چيکان عليا', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502902, N'دولت آباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502903, N'تجرکرم  پناه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502905, N'بدره', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502906, N'جوهان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502907, N'ده  کريشه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502908, N'چشمه  سنگي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502910, N'چغاجنگاعليا', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502911, N'سياسياه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502912, N'زواره  کوه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502913, N'زعفران', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502914, N'کمرسوراخ', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502915, N'ميرعزيزي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502916, N'کندهر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502917, N'قوچمي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502918, N'منوري', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502919, N'قلعه  شيان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502920, N'قلعه  ترک', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502921, N'قباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1502922, N'گردنگاه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503000, N'پاوه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503100, N'مرکزي  پاوه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503101, N'هولي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503102, N'خانقاه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503103, N'شمشير', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503104, N'منصوراقايي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503105, N'قشلاق', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503200, N'باينگان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503201, N'ماکوان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503202, N'دودان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503203, N'کلاشي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503204, N'مزران', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503205, N'شيوه  سر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503206, N'بانوره', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503300, N'نوسود', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503301, N'نودشه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503302, N'سيروان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503303, N'نيسانه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503901, N'دورسيان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503902, N'خجيج', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503903, N'بتوي  سراب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503904, N'گلال', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503905, N'ساتياري', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1503906, N'ياقلعه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504000, N'جوانرود', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504100, N'مرکزي  جوانرود', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504101, N'پلنگانه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504102, N'ساروخان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504103, N'شروينه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504104, N'بازان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504105, N'زيلان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504200, N'ثلاث باباجاني', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504201, N'تازه  اباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504202, N'زمکان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504203, N'ميراباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504204, N'دشت حر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504205, N'قلقله', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504206, N'خانه  شور', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504207, N'ده  شيخ', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504208, N'ازگله', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504300, N'روانسر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504302, N'حسن آباد -  روانسر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504303, N'بدر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504304, N'برهان الدين', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1504901, N'خانيله', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505000, N'سرپل  ذهاب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505100, N'مرکزي  سرپل  ذهاب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505101, N'قلعه  شاهين -  مرکزي  سرپل  ذهاب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505102, N'ترک ويس', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505103, N'حومه  سرپل', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505104, N'قره  بلاغ', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505105, N'دشت ذهاب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505106, N'ميرميرو', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505107, N'پشت تنگ', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505108, N'بزميراباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505109, N'سرقلعه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505110, N'تپه  رش', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505111, N'جيگران', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505112, N'گرده  نو', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505113, N'بشيره  باطلاق', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505114, N'ريزه  وندنجف', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1505115, N'دربندزرد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506000, N'سنقر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506100, N'مرکزي  سنقر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506101, N'سطر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506102, N'باوله', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506103, N'اگاهان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506104, N'اگاه  عليا', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506105, N'سراب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506106, N'گزنهله', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506107, N'آب باريک', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506108, N'آب باريک عليا', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506109, N'گاورود', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506110, N'قمام', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506111, N'کيونانات', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506112, N'کيونان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506113, N'پارسينه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506114, N'فارسينج', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1506901, N'جان احمد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1507000, N'قصرشيرين', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1507100, N'مرکزي  قصرشيرين', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1507101, N'الوند', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1507102, N'خسروي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1507103, N'فتح  اباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1507104, N'اقابرار', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1507105, N'نصراباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1507106, N'کورکهرک', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1507200, N'سومار', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1507201, N'قلعه  سومار', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508000, N'صحنه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508100, N'مرکزي  صحنه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508101, N'درکه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508102, N'گاماسياب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508103, N'گاوگل  عليا', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508104, N'خدابنده  لو', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508105, N'دهلق', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508106, N'هجر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508107, N'سمنگان عليا', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508200, N'دينور', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508201, N'ميان راهان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508202, N'حر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508203, N'مويينه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1508204, N'کندوله', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1509000, N'کنگاور', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1509100, N'مرکزي  کنگاور', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1509101, N'گودين', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1509102, N'فش', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1509103, N'کرماجان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1509104, N'خزل  غربي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1509105, N'سراب دهلر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1509106, N'قزوينه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1509901, N'فشخوان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510000, N'گيلانغرب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510100, N'مرکزي  گيلانغرب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510101, N'ديره', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510102, N'جوب باغان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510103, N'چله', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510104, N'قمرعلي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510105, N'حومه -  مرکزي  گيلانغرب', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510106, N'گورسفيد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510107, N'ويژنان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510108, N'نيان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510200, N'گواور', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510201, N'حيدريه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510202, N'سوخورنامدارعبدي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510203, N'سرمست', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510901, N'هنار', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510902, N'سوخودرشيد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510903, N'مرجان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510904, N'ميرابه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510905, N'عليرضاوندي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510906, N'صيدمحمدي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510907, N'گراويان سفلي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510908, N'زرگوشه  چله', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1510909, N'چشم  مورن', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1511000, N'هرسين', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1511100, N'مرکزي  هرسين', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1511101, N'حومه -  مرکزي  هرسين', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1511102, N'چقاکبود', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1511103, N'چشمه  کبود', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1511200, N'بيستون', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1511201, N'چم  جمال', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1511202, N'شيرز', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1511203, N'چهر', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599901, N'ميان رود', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599902, N'کوراني', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599903, N'کمره', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599904, N'دروفرامان', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599905, N'کليايي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599906, N'قلعه  گري', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599907, N'صيداباد', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599908, N'بيلوار', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599910, N'بيوه  شيخ', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599911, N'پاطاق', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599912, N'تالاندشت', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599913, N'جگرلو', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599914, N'بشيوه', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599915, N'چمچال', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599916, N'کفرود', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599917, N'قلعه  سبزي', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599918, N'باباخاني', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1599919, N'بايروند', N'کرمانشاه', 15)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1600000, N'استان خوزستان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601000, N'اهواز', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601100, N'مرکزي  اهواز', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601101, N'حميديه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601102, N'کوت عبدالله', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601103, N'بهر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601104, N'غيزانيه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601105, N'سويسه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601106, N'ابونانگه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601107, N'مشرحات', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601108, N'کرخه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601109, N'دهکده', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601110, N'عناقچه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601111, N'گبيريک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601112, N'الهايي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601113, N'اسماعيليه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601114, N'صفحه  يک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601200, N'باوي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601201, N'ملاثاني', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601202, N'صليعه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601203, N'ويس', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601204, N'زرگان ابوفاضل', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601901, N'سربندر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601902, N'البوفاضل', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601903, N'بيت محارب', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601905, N'دين', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601906, N'تل  بومه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601907, N'ذوب الحان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601908, N'بحره', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601909, N'شعط', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601910, N'سرراحي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601911, N'منصوريه  يک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601912, N'غريبه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601913, N'عوده', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601914, N'ملانافي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1601915, N'ام  الطهر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602000, N'آبادان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602100, N'مرکزي  ابادان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602101, N'بهمنشيرجنوبي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602102, N'ابوشانک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602103, N'بهمنشيرشمالي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602104, N'فرخزاد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602105, N'شلاهي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602106, N'ثوامر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602107, N'فاو', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602108, N'منطقه  ازاداروند', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602200, N'اروندکنار', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602201, N'مينوبار', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602202, N'کوت شنوف', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602203, N'نواباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602204, N'انبار', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602205, N'نصار', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602206, N'فرخ  پي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602207, N'نرابتر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602901, N'شطيط', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602902, N'طره  خضر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602903, N'چهارمحال', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602904, N'دره  کنار', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1602906, N'بريم', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1603000, N'انديمشک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1603100, N'مرکزي  انديمشک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1603101, N'حومه -  مرکزي  انديمشک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1603102, N'شهربابک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1603200, N'الوارگرمسيري', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1603201, N'حسينيه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1603202, N'قيلاب', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1603203, N'سرخکان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1603204, N'مازو', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604000, N'ايذه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604100, N'مرکزي  ايذه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604101, N'پيان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604102, N'پشت پيان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604103, N'حومه  شرقي -  مرکزي  ايذه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604104, N'کولفرج', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604105, N'حومه  غربي -  مرکزي  ايذه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604106, N'راسوند', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604107, N'سوسن شرقي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604108, N'جنگه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604109, N'سوسن غربي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604110, N'ترشک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604111, N'مرغا', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604112, N'چم  ريحان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604113, N'هلايجان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604114, N'چنارستان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604200, N'دهدز', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604201, N'دنباله  رودشمالي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604202, N'باجول', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604203, N'دنباله  رودجنوبي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604204, N'ده  نوکيزوک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604901, N'نرگي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604902, N'سوهان عليا', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604903, N'لاين', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604904, N'قلعه  سرد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1604905, N'قلعه  سرخ', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605000, N'باغ  ملک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605100, N'مرکزي  باغ  ملک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605101, N'ميداود', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605102, N'ميداودسفلي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605103, N'رودزرد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605104, N'رودزردکايدرفيع', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605105, N'قلعه  تل', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605106, N'منگشت', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605107, N'ابوالعباس', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605200, N'صيدون', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605201, N'سرله', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605202, N'دالان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605204, N'هپرو', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605205, N'دورتو', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605901, N'ابشکر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605902, N'باغملا', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605903, N'کراوندعليا', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605904, N'گراوندعليا', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1605905, N'گراوندسفلي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1606000, N'بندرماهشهر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1606100, N'مرکزي  بندرماهشهر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1606101, N'جراحي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1606102, N'هشتچه  سفلي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1606200, N'اميديه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1606201, N'چاه  سالم', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1606202, N'اسياب', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1606300, N'بندرامام  خميني', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1606400, N'هنديجان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1606401, N'چهل  مني', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1606402, N'چم  خلف عيسي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607000, N'بهبهان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607100, N'مرکزي  بهبهان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607101, N'حومه -  مرکزي  بهبهان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607102, N'منصوريه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607103, N'دودانگه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607104, N'دودانگه  بزرگ', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607105, N'تشان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607106, N'مشهد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607200, N'اغاجاري', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607300, N'زيدون', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607301, N'درونک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607901, N'بيدبلند', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607902, N'بدلي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607903, N'کردستان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1607904, N'اميديه  عليا', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608000, N'خرمشهر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608100, N'مرکزي  خرمشهر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608101, N'حومه  شرقي -  مرکزي  خرمشهر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608102, N'حفارشرقي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608103, N'حومه  غربي -  مرکزي  خرمشهر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608104, N'پل  نو', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608105, N'غرب کارون', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608106, N'کفيشه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608107, N'شلمچه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608108, N'جزيره  مجنون', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608200, N'مينو', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608201, N'جزيره  مينو', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1608202, N'چومه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609000, N'دزفول', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609100, N'مرکزي  دزفول', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609101, N'شمس اباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609102, N'چغاميش', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609103, N'قبله  اي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609104, N'محمدبن جعفر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609200, N'سردشت', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609201, N'شهي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609202, N'وحدت', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609203, N'سيدولي  الدين', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609204, N'گوشه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609205, N'امام  زاده  سيدمحمود', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609206, N'شوي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609207, N'احمدفداله', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609208, N'فداله  عمران', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609209, N'ماهوربرنجي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609210, N'دره  کايد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609211, N'کول  سيرا', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609901, N'حسين برمله', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609902, N'پايين حجاز', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1609903, N'لاره', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610000, N'دشت ازادگان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610100, N'مرکزي  دشت ازادگان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610101, N'سوسنگرد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610102, N'حومه  شرقي -  مرکزي  دشت ازادگان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610103, N'جلاليه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610104, N'حومه  غربي -  مرکزي  دشت ازادگان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610105, N'برديه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610106, N'الله  اکبر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610107, N'جليزي  جنظله', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610200, N'بستان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610201, N'مهين اباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610202, N'سعيديه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610203, N'حاجي  سالم', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610300, N'هويزه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610301, N'سعيده', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610302, N'نيسان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610303, N'بني  نعامه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610304, N'بني  صالح', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610305, N'يزدنو', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610901, N'ناچرديه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610902, N'فيخي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610903, N'رفيع', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1610904, N'رميم', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611000, N'رامهرمز', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611100, N'مرکزي  رامهرمز', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611101, N'حومه  شرقي -  مرکزي  رامهرمز', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611102, N'باصدي  حاج  بارون', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611103, N'حومه  غربي -  مرکزي  رامهرمز', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611104, N'مربچه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611105, N'سلطان اباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611106, N'جايزان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611107, N'ابوالفارس', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611108, N'باروج', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611200, N'هفتگل', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611201, N'جارو', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611202, N'گزين', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611300, N'رامشير', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611301, N'ازاده', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611302, N'مشراکه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611303, N'عبدليه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611901, N'قلعه  حمود', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611902, N'تفت سفيد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1611903, N'جايزان کهنه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1612000, N'شادگان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1612100, N'مرکزي  شادگان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1612101, N'ابشار', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1612102, N'نهرجديد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1612103, N'بوزي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1612104, N'جفال', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1612105, N'حسيني', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1612107, N'خنافره', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1612108, N'خروسي  جنوبي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1612109, N'دارخوين', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1612901, N'غياضي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613000, N'شوش', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613100, N'مرکزي  شوش', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613101, N'سرخه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613102, N'صالح  مشطت', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613103, N'چنانه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613104, N'محمدصافي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613105, N'بن مطي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613106, N'شهرک بهرام', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613107, N'حسين آباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613108, N'عمله  تيمور', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613200, N'شاوور', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613201, N'اهودشت', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613202, N'مزرعه  يک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1613203, N'سيدعباس', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614000, N'شوشتر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614100, N'مرکزي  شوشتر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614101, N'سرداراباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614102, N'شعييه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614103, N'گوريه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614104, N'شهيدمدرس', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614105, N'درخزينه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614106, N'ميان اباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614107, N'عرب حسن', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614108, N'ميان اب شمالي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614109, N'مهدي  اباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614200, N'کتوند', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614201, N'جنت مکان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614202, N'عقيلي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614203, N'سماله', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614901, N'سيدحسين', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614902, N'لنگر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1614903, N'صوفان سفلا', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615000, N'مسجدسليمان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615100, N'مرکزي  مسجدسليمان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615101, N'تل  بزان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615102, N'رضااباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615103, N'تمبي  گلگير', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615104, N'گلگير', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615105, N'جهانگيري', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615106, N'هفت شهيدان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615200, N'انديکا', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615201, N'قلعه  خواجه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615202, N'کوشک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615203, N'کوشکک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615204, N'ابژدان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615205, N'جعفرآباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615206, N'شلال  دشتگل', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615207, N'پااب شلال', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615208, N'چلو', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615209, N'زاووت', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615210, N'للروکتک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615211, N'کتک', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615300, N'لالي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615301, N'دشت لالي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615302, N'ططر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615303, N'سادات', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615304, N'دره  بوري', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615305, N'حتي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615306, N'جاستون شهه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615307, N'ولي  اباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615901, N'شانزده  ميل', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615902, N'هتکل', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615903, N'قلعه  زراسي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615904, N'نفتون', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615905, N'دشت گل', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1615906, N'توبزان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699915, N'ام  الصخر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699916, N'بنوار', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699917, N'خران', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699918, N'بيدله', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699919, N'ايوه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699920, N'ترکدز', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699921, N'جانکي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699922, N'بايمان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699923, N'بتوند', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699924, N'بردان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699925, N'چم  هاشم', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699926, N'شمعون', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699927, N'شرقي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699928, N'شرفه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699929, N'شاه  ولي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699930, N'شاهپور', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699931, N'شادبه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699932, N'کهبرغربي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699933, N'سلاحي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699934, N'سرطا', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699935, N'زويدي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699936, N'ريمچه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699937, N'رويس', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699938, N'ناظر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699939, N'رمله', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699940, N'رفيوه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699941, N'رستم  اباد', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699942, N'دنباله  رود', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699943, N'محرزي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699944, N'خين', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699945, N'ماهشهر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699946, N'ليوس', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699947, N'لهبري  شرقي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699948, N'ميان اب شوشتر', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699949, N'قلعه  کعبي', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699950, N'قلعه  شيخ', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699951, N'گندلوز', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699952, N'عمه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699953, N'معمره', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699954, N'صفاييه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699955, N'ميانکوه', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699956, N'شهرياري', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699957, N'هيرو', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699958, N'نهريوسف', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699959, N'نهرهاشم', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699960, N'ننادگان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1699961, N'هوزگان', N'خوزستان', 16)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1700000, N'استان فارس', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701000, N'شيراز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701100, N'مرکزي  شيراز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701101, N'دراک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701102, N'صادقيه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701103, N'بيدزرد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701104, N'بيدزردسفلي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701105, N'سياخ  دارنگون', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701106, N'کدنج', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701107, N'داريان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701108, N'قره  باغ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701110, N'کفترک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701111, N'نصراباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701200, N'ارژن', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701201, N'دشت ارژن', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701202, N'چهل  جشمه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701203, N'قره  چمن', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701204, N'خانه  زنيان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701205, N'کوهره  سرخي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701206, N'ريچي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701300, N'زرقان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701301, N'لپويي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701302, N'بندامير', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701400, N'سروستان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701401, N'کت گنبد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701402, N'کوهنجان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701403, N'مهارلو', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701500, N'کربال', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701501, N'خرامه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701502, N'کفدهک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701503, N'دهقانان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701504, N'سفلي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701505, N'خيراباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701506, N'خيرابادتوللي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701507, N'رحمت اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701600, N'کوار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701601, N'طسوج', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701602, N'فرمشکان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701603, N'دهشيب', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701604, N'اکبراباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701901, N'کورکي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701902, N'شاهي  جان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701903, N'شافل  بيگي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701904, N'سيروج', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701905, N'سهل  اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701906, N'کوشک مولا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701907, N'کوشک عباسعلي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701908, N'کوشک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701909, N'کمال  اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701910, N'قصرشهريار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701911, N'قشقايي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701912, N'گوسيه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701913, N'فيروزي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701914, N'فلات', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701915, N'شيخعلي  چوپان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701916, N'چنارراهدا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701917, N'دوکوهک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701918, N'پشت پله', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701919, N'تيره  ارخلو', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701920, N'تيره  قرقاني', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701921, N'تيره  موصلو', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701922, N'تيره  نره', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701923, N'دوامان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701924, N'اجوار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701925, N'بس کوهک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701926, N'دهکره', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701927, N'اغارودادان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1701928, N'تيره  سارويي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702000, N'آباده', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702100, N'مرکزي  اباده', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702101, N'صغاد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702102, N'بهمن', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702104, N'بيدک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702105, N'سورمق', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702200, N'قنقري', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702201, N'صفاشهر', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702202, N'قشلاق', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702203, N'خرمي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702901, N'ييرک اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1702902, N'شيدان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703000, N'بوانات', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703100, N'مرکزي  بوانات', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703101, N'سوريان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703103, N'باغستان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703104, N'جشنيان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703106, N'مزايجان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703200, N'سرچهان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703201, N'کره  اي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703202, N'توجردي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703203, N'باغ  صفا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703901, N'فخراباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1703902, N'بزم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1704000, N'استهبان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1704100, N'مرکزي  استهبان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1704101, N'ايج', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1704200, N'رونيز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1704201, N'رونيزعليا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1704202, N'خير', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1704203, N'ماه  فرخان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705000, N'اقليد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705100, N'مرکزي  اقليد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705101, N'خنجشت', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705102, N'حسن آباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705103, N'خسرووشيرين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705104, N'شهرميان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705105, N'احمد آباد -  مرکزي  اقليد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705200, N'سده', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705201, N'دژکرد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705202, N'اسلاميه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705203, N'اسپاس', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1705204, N'بکان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706000, N'جهرم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706100, N'مرکزي  جهرم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706101, N'جلگاه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706102, N'حيدراباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706103, N'کوهک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706104, N'خرم آباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706200, N'خفر', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706201, N'خاوران', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706202, N'باب انار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706203, N'سفيدار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706204, N'اسماعيل آباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706205, N'راهگان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706206, N'تادوان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706207, N'علي آباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706208, N'گل  برنجي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706300, N'سيمکان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706301, N'پشت پر', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706302, N'جرمشت بالا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706303, N'پل  به  بالا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706304, N'دوزه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706305, N'پل  به  پايين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706306, N'شاغون', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706400, N'کرديان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706401, N'قطب اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706402, N'علويه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1706901, N'صادق  اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707000, N'داراب', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707100, N'مرکزي  داراب', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707101, N'جنت شهر', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707102, N'قلعه  بيابان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707103, N'بالش', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707104, N'سنگ چارک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707105, N'پاسخن', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707106, N'بختاجرود', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707107, N'فسارود', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707108, N'مادوان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707109, N'نصروان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707110, N'هشيوار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707111, N'شهنان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707112, N'قريه  الخير', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707113, N'ده  خيرعليا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707200, N'حاجي آباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707201, N'ايزدخواست', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707202, N'شهرپير', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707203, N'دبيران', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707204, N'زيراب', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707205, N'خسويه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707206, N'قلاقوشه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707207, N'قلانوييه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707300, N'رستاق', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707301, N'کوهستان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707302, N'تل  بارگاه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707400, N'فورگ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707401, N'دوبرجي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707402, N'ابشور', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707403, N'فدامي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707500, N'زرين دشت', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1707901, N'سلطان اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708000, N'سپيدان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708100, N'مرکزي  سپيدان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708101, N'اردکان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708102, N'خفري', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708103, N'بهرغان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708104, N'همايجان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708105, N'ده  پاگا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708106, N'کمهر', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708200, N'بيضا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708201, N'هرابال', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708202, N'بانش', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708203, N'کوشک هزار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708204, N'علي  ابادتنگ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708205, N'مليون', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708207, N'پشت باغ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708208, N'تنگ خياره', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708300, N'دشمن زياري', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708301, N'دولت آباد -  دشمن زياري', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708302, N'هرايجان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708303, N'سرناباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708304, N'ميرزامحمدي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708902, N'شول', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708903, N'شيخ  عبود', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708904, N'چنار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708905, N'دالين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708906, N'تيره  سهرابخاني', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1708907, N'خلار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709000, N'فسا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709100, N'مرکزي  فسا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709101, N'کوشک قاضي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709102, N'جنگل', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709103, N'مقابري', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709104, N'صحرارود', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709200, N'ششده  وقره  بلاغ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709201, N'ششده', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709202, N'قره  بلاغ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709203, N'دوگان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709300, N'شبيکوه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709301, N'زاهدشهر', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709302, N'ميانده', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709303, N'فدشکوييه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709400, N'نوبندگان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1709902, N'ال  قلي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710000, N'فيروزاباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710100, N'مرکزي  فيروزاباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710101, N'احمد آباد -  مرکزي  فيروزاباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710102, N'جايدشت', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710200, N'ميمند', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710201, N'پرزيتون', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710202, N'خواجواي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710203, N'جوکان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710204, N'دادنجان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710300, N'فراشبند', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710301, N'نوجين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710302, N'دهرم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710303, N'اويز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710304, N'دژگاه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710305, N'دولت آباد -  فراشبند', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710400, N'قيروکارزين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710401, N'مبارک اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710402, N'افزر', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710403, N'شهرک جنوبي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710404, N'هنگام', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710405, N'فتح  اباد -  قيروکارزين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710406, N'زاخرويه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710407, N'مزرعه  پهن', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710901, N'شبانکاره', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710902, N'محمدآباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710903, N'قصري  صم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710904, N'هفت اسياب', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710905, N'غليارد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710906, N'عليا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710907, N'خپيص', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710908, N'بيان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710909, N'خمار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710910, N'باباعلم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1710911, N'بابانجم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711000, N'کازرون', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711100, N'مرکزي  کازرون', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711101, N'قايميه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711102, N'بليان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711103, N'مهرنجان -  مرکزي  کازرون', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711104, N'دريس', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711105, N'شاپور', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711106, N'انارستان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711107, N'امامزاده  سيدحسين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711108, N'سيدحسين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711200, N'جره  وبالاده', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711201, N'جره', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711202, N'دادين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711203, N'دادين عليا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711204, N'فامور', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711205, N'نرگس زار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711300, N'خشت وکمارج', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711301, N'خشت', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711302, N'کنارتخته', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711303, N'کمارج', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711400, N'کوهمره', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711401, N'دشت برم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711402, N'کلاني', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711403, N'نودان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1711901, N'دوان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712000, N'لار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712100, N'مرکزي  لار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712101, N'حومه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712102, N'لطيفي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712103, N'درزوسابيان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712104, N'درز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712105, N'دهکويه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712106, N'صحراي  باغ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712107, N'باغ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712200, N'اوز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712201, N'بيدشهر', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712202, N'کوره', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712203, N'فيشور', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712300, N'بيرم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712301, N'بالاده', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712302, N'عمادده', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712400, N'گراش', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712401, N'ارد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712402, N'فداغ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712500, N'جويم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712501, N'بنارويه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712502, N'هرم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712503, N'بلغان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712600, N'خنج', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712601, N'سيف اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712602, N'محمله', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712901, N'کهنه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712902, N'ديده  بان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1712903, N'ده  نو', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713000, N'لامرد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713100, N'مرکزي  لامرد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713101, N'خوزي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713102, N'سيگار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713103, N'وراوي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713104, N'چاه  ورز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713200, N'اشکنان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713201, N'اهل', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713202, N'کال', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713300, N'علامرودشت', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713301, N'چاه  عيني', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713302, N'خيرگو', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713400, N'مهر', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713401, N'اردوان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713402, N'اردوان عليا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713500, N'گله  دار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713501, N'اسير', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1713901, N'چاه  کدري', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714000, N'مرودشت', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714100, N'مرکزي  مرودشت', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714102, N'رامجرديک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714103, N'کوه  سبز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714104, N'نقش رستم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714105, N'زنگي  اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714106, N'رودبال', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714107, N'فتح  اباد -  مرکزي  مرودشت', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714108, N'کناره', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714109, N'مجداباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714200, N'سيدان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714201, N'خفرک عليا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714202, N'رحمت', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714203, N'کره  طاوي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714300, N'ارسنجان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714301, N'خبريز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714302, N'شوراب', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714303, N'علي  ابادملک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714400, N'سعادت اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714401, N'پاسارگاد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714402, N'قادراباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714403, N'کمين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714404, N'جيسقان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714405, N'سرپنيران', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714406, N'نعيم  اباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714407, N'مشهدمرغاب', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714408, N'مادرسليمان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714500, N'درودزن', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714501, N'ابرج', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714502, N'بيدگل', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714503, N'رامجرددو', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714504, N'کوشکک -  درودزن', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714600, N'کامفيروز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714601, N'خرم  مکان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714602, N'کامفيروزجنوبي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714603, N'مشهدوبيلو', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714604, N'کامفيروزشمالي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714605, N'خانمين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1714901, N'خزرک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715000, N'ممسني', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715100, N'مرکزي  ممسني', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715101, N'نوراباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715102, N'بکش دو', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715103, N'اهنگري', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715104, N'بکش يک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715105, N'گچگران', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715106, N'جاويدماهوري', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715107, N'مورکي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715108, N'جوزار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715109, N'مهرنجان -  مرکزي  ممسني', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715110, N'فهليان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715111, N'فهليان عليا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715112, N'مشايخ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715200, N'ماهورميلاني', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715201, N'ماهور', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715202, N'بابامنير', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715203, N'ميشان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715204, N'ميشان عليا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715300, N'رستم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715301, N'پشتکوه  رستم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715302, N'چهارطاق', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715303, N'رستم  دو', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715304, N'دهنومقيمي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715305, N'رستم  يک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715306, N'مصيري', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715307, N'رستم  سه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715308, N'کوپن عليا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715901, N'دره  گرم', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715902, N'تل  بيشه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715903, N'تل  ريزي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715904, N'تل  سياه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715905, N'سنگسر', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715906, N'جابه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715908, N'چاه  انجير', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715909, N'اکبري', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715910, N'دودانگه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715911, N'شتکان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715912, N'کلگاه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715913, N'کجايي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715914, N'لوان وسطي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715915, N'ميرزاقلي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715916, N'سنگر', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715917, N'ميرزاامان الله', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715918, N'شوسني', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715919, N'مشان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715920, N'نزاع  بزرگ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715921, N'مرغ  بزرگ', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715922, N'شيراسپاري', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1715923, N'تيره  سادات', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716000, N'ني  ريز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716100, N'مرکزي  ني  ريز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716102, N'نصيراباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716103, N'هرگان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716200, N'اباده  طشک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716201, N'بختگان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716202, N'کوشکک -  اباده  طشک', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716203, N'حنا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716204, N'تم  شولي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716300, N'پشتکوه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716302, N'دهچاه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1716303, N'قطرويه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799901, N'ده  دشت', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799903, N'هگان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799904, N'کلاکلي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799905, N'کاکون', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799906, N'اسفندآباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799907, N'قير', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799908, N'تنگ حنا', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799909, N'تنگ رودبال', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799910, N'جاويدلله', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799911, N'اربعه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799912, N'مهراباد', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799913, N'شاهپور', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799914, N'شاميجان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799915, N'کوشکسار', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799916, N'زاهگان', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799917, N'رستاق  نيريز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799918, N'رستاق  داراب', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799921, N'دگاه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799922, N'فطرويه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799923, N'شيبکوه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799925, N'چهاردانگه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799927, N'کوهمره  شيراز', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799928, N'خضرک سفلي', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799929, N'ايرج', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799930, N'تراکمه', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1799931, N'کارزين', N'فارس', 17)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1800000, N'استان کرمان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801000, N'کرمان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801100, N'مرکزي  کرمان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801101, N'باغين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801102, N'اختياراباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801103, N'سراسياب فرسنگي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801104, N'درختنگان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801105, N'ده  لولو', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801106, N'زنگي  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801107, N'معدن ابدشت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801200, N'چترود', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801201, N'حرجند', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801202, N'کويرات', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801204, N'معزيه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801205, N'هوتک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801206, N'هروز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801207, N'هجدک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801300, N'راين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801301, N'ده  ميرزا', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801302, N'حسين ابادگروه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801303, N'گروه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801400, N'راور', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801402, N'رودر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801500, N'شهداد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801501, N'اندوهجرد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801502, N'تکاب', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801503, N'استحکام', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801504, N'سيرچ', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801505, N'شوراباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801600, N'گلباف', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801601, N'جوشان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801602, N'کشيت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801700, N'ماهان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801701, N'جوپار', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801702, N'لنگر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801703, N'قناتفستان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801704, N'محي  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801705, N'مهي  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801706, N'عرب اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801707, N'حسين ابادمهدي  قلي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801708, N'سکنج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801902, N'ديکوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801903, N'پشته  شيران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801904, N'باداموييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801905, N'چاه  کهنوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801906, N'فرح  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1801907, N'طاهراباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802000, N'بافت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802100, N'مرکزي  بافت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802101, N'بزنجان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802102, N'خبر -  مرکزي  بافت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802103, N'دشتاب', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802105, N'دهسرد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802106, N'پتکان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802107, N'فتح  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802108, N'بيدکردوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802109, N'کيسکان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802110, N'کرين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802111, N'گوغر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802112, N'اميرآباد -  مرکزي  بافت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802200, N'ارزوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802201, N'شاهماران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802202, N'صوغان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802203, N'سرخان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802204, N'وکيل  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802300, N'رابر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802301, N'اسکر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802302, N'جواران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802304, N'سيه  بنوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802305, N'هنزا', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802306, N'کوير', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802307, N'بادگلويه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802308, N'ديوران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802309, N'اسفنا', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802901, N'چهارطاق', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802902, N'کيکان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802903, N'صالح  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802904, N'شريک اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802905, N'کهک زردشت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802906, N'شاه  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802908, N'هنکنوليه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802909, N'هارموييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802910, N'گريستان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802911, N'کيجوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802912, N'قلاطوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802913, N'گوسلطاني', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802914, N'گوراندشت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802915, N'گنوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802916, N'ميبدان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802917, N'گلينوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802918, N'مهرصالح', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802919, N'مغوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802920, N'طيطوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802921, N'گرگونيه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802922, N'طرطيه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802923, N'خسرواباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802924, N'امامزاده', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802925, N'حسن آباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802926, N'ديخوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802927, N'بنگان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802928, N'حورگويه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802929, N'دامنه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802930, N'دره  مريد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802931, N'رسف الدين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802932, N'بيدشک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802933, N'بيدشيرين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802935, N'ابلق  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802936, N'باغ  خنک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802937, N'ده  نو', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802939, N'سنگ پهن', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802940, N'تينز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802941, N'خيارلدران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802942, N'ده  ساجر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802943, N'ادرنجان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802944, N'رودخانه  سلطاني', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802945, N'راسجر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1802946, N'بستان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803000, N'بردسير', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803100, N'مرکزي  بردسير', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803101, N'قريت العرب', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803102, N'قلعه  عسگر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803103, N'کوه  پنج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803104, N'ماهونک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803105, N'لاله  زار', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803106, N'مشيز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803107, N'دشتکار', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803108, N'نگار', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803901, N'ماه  خاتوني', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803902, N'مورسران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803903, N'کرپوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803904, N'گنبد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803905, N'کنگوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803906, N'صاحب اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803907, N'چنارکف', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803908, N'بيدخيزي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803909, N'بيدبستان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803910, N'بيدخان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803911, N'بيدستان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803912, N'ابرجو', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803913, N'تکيه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803914, N'باغ  حسن', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803916, N'تنگويه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803917, N'ده  پايين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1803918, N'ده  گر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804000, N'بم', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804100, N'مرکزي  بم', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804101, N'بروات', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804103, N'خواجه  عسگر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804104, N'دهکري', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804105, N'ده  بيد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804106, N'روداب شرقي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804107, N'اب شورنظام  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804108, N'روداب غربي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804109, N'کروک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804110, N'کرک ونارتيج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804111, N'پشت رود -  مرکزي  بم', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804200, N'ريگان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804201, N'محمدابادريگان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804202, N'چاه  دگال', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804203, N'حسين ابادچاه  هدگال', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804204, N'گنبکي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804205, N'محمدابادگنبکي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804206, N'گاوکان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804207, N'دهنه  عباسطي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804300, N'فهرج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804301, N'برج  اکرم', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804302, N'مرادابادپشترود', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804303, N'ابراهيم آباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804400, N'نرماشير', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804401, N'عزيزاباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804402, N'ده  وسط', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804403, N'پشت رود -  نرماشير', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804901, N'سيدي  دامنه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804902, N'مرغک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804903, N'نارتيج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804904, N'محمدابادکرک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804905, N'همت اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804906, N'قيرابادريگان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804907, N'نظام  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804908, N'گلستان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804909, N'دريجان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804910, N'ابارق', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1804911, N'ده  بکري', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805000, N'جيرفت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805100, N'مرکزي  جيرفت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805101, N'اسماعيلي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805102, N'بلوک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805103, N'اسلام آباد -  مرکزي  جيرفت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805104, N'ده  پيش سفلي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805105, N'اسفندقه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805106, N'دولت آباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805108, N'کريم  ابادسفلي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805109, N'خاتون آباد -  مرکزي  جيرفت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805110, N'گنج  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805111, N'دهنوفتح  المبين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805112, N'خاتون ابادزنگيان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805113, N'هليل', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805114, N'کهوروييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805200, N'جبالبارز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805201, N'رضوان -  جبالبارز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805202, N'ميجان سفلي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805203, N'سفدر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805204, N'مسکون', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805205, N'محمدآباد -  جبالبارز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805300, N'ساردوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805301, N'درب بهشت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805302, N'دلفارد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805303, N'رضي  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805304, N'گور', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805400, N'عنبراباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805401, N'امجز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805402, N'دهنه  کمرکان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805403, N'جهاداباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805404, N'دوساري', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805405, N'علي آباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805406, N'علي  ابادقديري', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805407, N'گرمسار', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805408, N'گرمسالاررضا', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805409, N'محمدآباد -  عنبراباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805410, N'خضراباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805411, N'نرگسان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805412, N'کلجک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805413, N'محمدابادباباشهري', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805414, N'مردهک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805415, N'کرکان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805416, N'گرم  عليا', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805417, N'عماداباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805418, N'حسين ابادلولي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805419, N'دزرران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805420, N'رودفرق', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805901, N'سيف اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805902, N'کنزرک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805903, N'کلرود', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805904, N'قنات کلانتر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805905, N'هوکرد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805906, N'علي  ابادميرخان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805907, N'مگسي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805908, N'طوحان عليا', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805909, N'خونسرخ', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805910, N'سبزواران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805911, N'بهرامي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805912, N'پاي  اندر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805913, N'دهنوحسين کرمشاه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805914, N'سنگراه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805915, N'دشت کوچ', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805916, N'سرجاز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805917, N'جلگه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805918, N'جنگا', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1805919, N'زنگنان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806000, N'رفسنجان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806100, N'مرکزي  رفسنجان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806101, N'مس سرچشمه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806102, N'ازادگان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806103, N'رضااباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806104, N'اسلاميه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806105, N'هرمزاباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806106, N'بهرمان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806107, N'نعمت اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806108, N'خنامان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806109, N'دره  دران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806110, N'داوران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806112, N'رزم  اوران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806113, N'لاهيجان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806114, N'رضوان -  مرکزي  رفسنجان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806115, N'اسماعيل آباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806116, N'سرچشمه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806117, N'شهرک سرچشمه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806118, N'کبوترخان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806119, N'فردوس', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806120, N'فردوسيه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806200, N'کشکوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806201, N'راويز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806202, N'حوم  الدين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806203, N'شريف اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806300, N'انار', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806301, N'بياض', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806302, N'لطف اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806304, N'حسين ابادامين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806305, N'احمد آباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806901, N'نوق', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806902, N'همت ابادعليا', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806903, N'کهن', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806904, N'صادق  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806905, N'يوسف اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806906, N'کرشک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806907, N'لشگونيه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806908, N'گلوسالار', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806909, N'چناروييه  ابوالحسن', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806910, N'رييس اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806912, N'داوداباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806913, N'حميداباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806914, N'بي  بي  حيات', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806915, N'ده  بالا', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806916, N'باب کهکين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806917, N'جواديه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806918, N'ارجاس', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1806919, N'نظم  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807000, N'زرند', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807100, N'مرکزي  زرند', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807101, N'کيانشهر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807102, N'خانوک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807103, N'اسلام آباد -  مرکزي  زرند', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807104, N'جرجافک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807105, N'حتکن', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807106, N'دشت خاک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807107, N'سرينان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807108, N'احمدي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807109, N'سيرنر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807110, N'طغرالجرد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807111, N'محمدآباد -  مرکزي  زرند', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807112, N'وحدت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807113, N'بهااباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807114, N'يزدان اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807115, N'ده  فياض', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807200, N'کوهبنان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807201, N'جور', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807202, N'خرمدشت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807901, N'شکراباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807902, N'گزوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807903, N'حسين آباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1807904, N'تاج  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808000, N'سيرجان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808100, N'مرکزي  سيرجان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808101, N'بلورد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808102, N'پاريز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808103, N'چهارگنبد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808105, N'زيداباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808106, N'سعادت اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808109, N'حاجي آباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808110, N'محمودآباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808111, N'ملک اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808112, N'نجف اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808901, N'چناربرين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808902, N'آباده', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808903, N'حجت اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808906, N'اميرآباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808907, N'حکمي  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808908, N'دارستان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808909, N'ده  علي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808910, N'دهنو', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808911, N'پسوجان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808912, N'روچون', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808913, N'اب بندباغ', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808914, N'خيراباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808915, N'اسحق  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808916, N'ده  شير', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808917, N'تذرج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808918, N'باغ  خشک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808919, N'خرم آباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808920, N'چشمه  نعمت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808921, N'کهن سور', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808922, N'همسريش', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808923, N'کران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808924, N'نصرت اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808925, N'کاظم  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808926, N'گهرو', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808927, N'قاسم  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808928, N'علي  ابادخنج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808929, N'عزت اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808930, N'محمودابادحسين صفر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1808931, N'هنديز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809000, N'شهربابک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809100, N'مرکزي  شهربابک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809101, N'دهج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809102, N'استبرق', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809103, N'پاقلعه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809104, N'مرج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809105, N'جوزم', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809106, N'خاتون آباد -  مرکزي  شهربابک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809107, N'خبر -  مرکزي  شهربابک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809108, N'خورسند', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809110, N'مدوارات', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809111, N'کم  سرخ', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809112, N'ميمند', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809901, N'ساراب', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1809902, N'روگوشوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810000, N'کهنوج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810100, N'مرکزي  کهنوج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810101, N'حومه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810102, N'چاه  حاجي  کردي  کرماني', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810103, N'ده  کهان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810104, N'بارگاه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810105, N'زه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810106, N'نخلستان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810200, N'رودبار', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810201, N'جازموريان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810202, N'زهکلوت', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810203, N'کوهستان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810204, N'برج  عباس اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810205, N'نهضت اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810300, N'فارياب', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810301, N'حور', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810302, N'حورپاسفيد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810303, N'کلاشگرد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810305, N'مهروييه  پايين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810400, N'قلعه  گنج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810401, N'شهرقلعه  گنج', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810402, N'رمشک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810403, N'چاه  دادخدا', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810404, N'مارز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810405, N'راين قلعه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810406, N'سرخ  قلعه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810407, N'سرخ  قلعه  عليا', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810408, N'کشميران', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810500, N'منوجان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810501, N'قلعه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810502, N'بجگان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810503, N'نودژ', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810504, N'نوراباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1810901, N'حيدراباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899901, N'چهارفرسخ', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899902, N'ريز', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899903, N'سربنان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899904, N'آبگرم', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899905, N'سردر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899906, N'سبلوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899907, N'حصين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899908, N'حومه  غربي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899909, N'بهراسمان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899910, N'بيدخون', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899911, N'بهرامجرد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899912, N'بيژن اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899913, N'پشتکوه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899914, N'دشت تاک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899916, N'درمزار', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899917, N'تتنگوييه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899918, N'زر', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899919, N'تهرود', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899920, N'دارزلين', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899921, N'جميل  اباد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899922, N'دنباله  رود', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899923, N'سرمشک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899924, N'بشاگردشرقي', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899925, N'گلاشگرد', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899926, N'سياه  کوه', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899927, N'کوه  نيان', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899928, N'کوشک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899929, N'مزارع', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899930, N'هشون', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899931, N'گوک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1899932, N'گزک', N'کرمان', 18)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1900000, N'استان خراسان رضوي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901000, N'مشهد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901100, N'مرکزي  مشهد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901101, N'تبادگان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901102, N'فاز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901103, N'طوس', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901104, N'کاظم  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901105, N'کارده', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901106, N'کارده  نو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901107, N'ميان ولايت -  مرکزي  مشهد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901108, N'عسگريه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901109, N'کنويست', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901200, N'احمد آباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901201, N'پيوه  ژن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901202, N'امام  تقي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901203, N'سرجام', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901204, N'ملک اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901300, N'رضويه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901301, N'ابروان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901302, N'پايين ولايت -  رضويه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901303, N'کلاته  منار', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901304, N'ميامي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901400, N'طرقبه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901401, N'شانديز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901402, N'ارچنگ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901403, N'حصارگلستان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901500, N'کلات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901501, N'پساکوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901502, N'اميرآباد -  کلات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901503, N'زاوين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901504, N'زوسفلي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901505, N'کبودگنبد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901506, N'جليل  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901901, N'دوغارون', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901902, N'خطايان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901903, N'ابراهيم آباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901904, N'تپه  نادر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901905, N'بازه  شاخ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901906, N'بافو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901907, N'سحنگ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901908, N'نخودک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901909, N'کنگ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901910, N'سلطان اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901911, N'هدايت اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901912, N'گرانک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901913, N'عنبران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901914, N'صالح  خاني', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901915, N'فتح  اباديزديها', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901916, N'حسن آباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1901917, N'نيش اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1902101, N'اذري', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1902103, N'دامنکوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1902104, N'چهاربرج', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1902105, N'زرق  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1902106, N'رويين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1902107, N'ايرج', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1902108, N'ميلانو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1902109, N'پرکانلو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1902201, N'بام', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1902901, N'کلاته  فرش', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1902902, N'کشتان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903101, N'الاداغ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903102, N'خوش منظر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903103, N'باباامان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903104, N'بدرانلو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903201, N'گرمه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903202, N'ميان دشت', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903203, N'کلاته  باقر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903208, N'گلستان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903209, N'رباطقره  بيل', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903210, N'ايور', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903302, N'جرگلان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903303, N'يکه  سعودپايين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903304, N'تنگه  راز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903305, N'غلامان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903401, N'گيفان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903402, N'گيفان عليا', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903502, N'جيرانسو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903503, N'گرماب', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903903, N'کهنه  کن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903904, N'ناوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1903905, N'ارکان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904103, N'باقران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904108, N'کاهشنگ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904109, N'مرک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904110, N'شاخنات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904203, N'براکوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904204, N'گل', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904205, N'قلعه  زري', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904303, N'گزيک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904304, N'فخرود', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904305, N'گسک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904402, N'مومن اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904404, N'نهارجان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904405, N'کلاته  سليمان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904901, N'سرخاب', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904902, N'شاهميران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904903, N'پخت', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904905, N'بشگز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904906, N'فراشاد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904907, N'کازار', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904908, N'کاخکوک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904909, N'نوتابچيک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1904910, N'گاخکوک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1905000, N'تايباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1905100, N'مرکزي  تايباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1905101, N'ميان ولايت -  مرکزي  تايباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1905102, N'مشهدريزه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1905103, N'پايين ولايت -  مرکزي  تايباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1905104, N'کاريز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1905105, N'کرات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1905200, N'باخزر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1905201, N'بالاولايت -  باخزر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1905202, N'قلعه  نوعليا', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906000, N'تربت جام', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906100, N'مرکزي  تربت جام', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906101, N'ميان جام', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906102, N'اسماعيل آباد -  مرکزي  تربت جام', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906103, N'جامرود', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906104, N'چشمه  گل', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906105, N'پايين جام', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906106, N'سميع  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906107, N'جلگه  موسي  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906108, N'موسي  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906200, N'نصراباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906201, N'کاريزان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906202, N'کاريزنو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906203, N'بالاجام', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906300, N'صالح  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906301, N'اسماعيل آباد -  صالح  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906302, N'باغ  کشمير', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906303, N'نقو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906304, N'جنت اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906305, N'قلعه  حمام', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906306, N'جعفريه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1906901, N'شفلو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907000, N'تربت حيدريه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907100, N'مرکزي  تربت حيدريه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907101, N'بالاولايت -  مرکزي  تربت حيدريه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907102, N'منظر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907103, N'پايين ولايت -  مرکزي  تربت حيدريه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907104, N'بوري  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907200, N'بايک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907300, N'جلگه  زاوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907301, N'دولت آباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907302, N'زاوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907303, N'کاريزک ناگهاني', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907304, N'سليمان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907305, N'چخماق', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907306, N'صفاييه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907400, N'رشتخوار', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907401, N'استانه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907402, N'باسفر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907403, N'جنگل', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907404, N'حسين آباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907500, N'فيض اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907501, N'ازغند', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907502, N'شادمهر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907503, N'مه  ولات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907504, N'مهنه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907600, N'کدکن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907601, N'بالارخ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907602, N'سرهنگ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907603, N'پايين رخ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907604, N'نسر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907605, N'ميان رخ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907606, N'رباطسنگ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907901, N'سرلگان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907902, N'داف', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907903, N'سهل  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907904, N'قوزان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907905, N'مظفريه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1907906, N'خماري', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1908000, N'چناران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1908100, N'مرکزي  چناران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1908101, N'خيراباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1908102, N'رادکان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1908103, N'بق  مج', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1908200, N'گلبهار', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1908201, N'بيزکي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1908202, N'محسن اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1908203, N'درزاب', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1908204, N'گوارشگ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1908205, N'گلمکان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909000, N'خواف', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909100, N'مرکزي  خواف', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909101, N'بالاخواف', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909102, N'چمن اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909103, N'ميان خواف', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909104, N'خرگرد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909105, N'سلامي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909200, N'سنگان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909201, N'پايين خواف', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909202, N'بستان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909203, N'نيازاباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909300, N'جلگه  زوزن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909301, N'زوزن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909302, N'کبير', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1909303, N'ابراهيمي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910000, N'درگز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910100, N'مرکزي  درگز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910101, N'تکاب -  مرکزي  درگز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910102, N'خاخيان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910200, N'چاپشلو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910201, N'قره  باشلو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910203, N'ميانکوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910204, N'کبکان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910300, N'لطف اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910301, N'ديباج', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910302, N'شيلگان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910303, N'هزارمسجد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910400, N'نوخندان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910401, N'درونگر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910402, N'شيخها', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910403, N'شهرستانه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910404, N'برج  قلعه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1910901, N'عوض محمد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911000, N'سبزوار', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911100, N'مرکزي  سبزوار', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911101, N'رباط', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911102, N'رباطسرپوش', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911103, N'قصبه  شرقي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911104, N'ايزي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911105, N'قصبه  غربي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911106, N'خسروگرد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911107, N'کراب', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911108, N'بلاش اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911200, N'جوين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911201, N'نقاب', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911202, N'بالاجوين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911203, N'حکم  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911204, N'پيراکوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911205, N'برغمد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911300, N'خوشاب', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911301, N'دره  يام', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911302, N'مشکان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911305, N'شم  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911306, N'رباطجز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911400, N'داورزن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911401, N'باشتين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911402, N'ريوند -  داورزن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911403, N'کاه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911405, N'مزينان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911500, N'روداب', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911501, N'خواشد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911502, N'بجدن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911503, N'فروغن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911504, N'قلعه  نوروداب', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911505, N'کوه  همايي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911506, N'اجنورد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911600, N'ششتمد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911601, N'بيهق', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911602, N'تکاب کوه  ميش', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911603, N'تندک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911604, N'ربع  شامات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911605, N'قلعه  ميدان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911606, N'شامکان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911700, N'جغتاي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911701, N'پايين جرين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911702, N'فراشيان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911703, N'ابوچناري', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911704, N'ميان جوين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911705, N'ريواده', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911706, N'دستوران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911707, N'محمدابادگفت', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911901, N'دزق', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911902, N'باداشيان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911903, N'ذرق', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911904, N'برزو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1911905, N'عباس اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912000, N'سرخس', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912100, N'مرکزي  سرخس', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912101, N'تجن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912103, N'کندکلي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912104, N'خانگيران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912105, N'گنبدلي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912200, N'مرزداران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912201, N'مزداوند', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912202, N'پل  خاتون', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912203, N'پسکمر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912204, N'گل  بي  بي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1912205, N'بزنکان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913101, N'حومه -  مرکزي  شيروان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913102, N'اميرآباد -  مرکزي  شيروان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913103, N'زيارت', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913104, N'سيوکانلو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913105, N'هنامه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913106, N'زوارم', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913107, N'گليان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913201, N'تکمران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913202, N'توکور', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913203, N'جيرستان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913204, N'کوسه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913205, N'قوشخانه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1913206, N'ينگي  قلعه  بالا', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914101, N'گلشن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914102, N'دشتغران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914103, N'منتظريه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914104, N'جوخواه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914105, N'نخلستان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914106, N'کريت', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914108, N'کوير', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914109, N'زنوغان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914110, N'پيرحاجات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914111, N'حلوان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914200, N'دستگردان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914202, N'کوه  يخاب', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914203, N'تپه  طاق', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914901, N'پي  استان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914902, N'ديهشک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914903, N'دهنوفاطمه  برات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1914904, N'جمز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1915104, N'برون', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1915106, N'خانوک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1915203, N'مصبعي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1915302, N'رقه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1915304, N'غني  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1916000, N'فريمان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1916100, N'مرکزي  فريمان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1916101, N'بالابند', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1916102, N'زرکک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1916103, N'سنگ بست', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1916104, N'فرهادگرد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1916200, N'قلندراباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1916201, N'سفيدسنگ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1916901, N'قلعه  نوفريمان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1916902, N'سودخر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1916903, N'سراسنگ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1917102, N'مهمويي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1917103, N'پسکوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1917202, N'اسلام آباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1917203, N'پيشکوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1917204, N'بيهود', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1917301, N'پترگان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1917304, N'شاسکوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1917305, N'ابيز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918000, N'قوچان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918100, N'مرکزي  قوچان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918101, N'سودلانه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918102, N'علي آباد -  مرکزي  قوچان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918103, N'شيرين دره', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918104, N'مزرج', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918105, N'دوغايي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918106, N'الماجق', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918107, N'قوچان عتيق', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918108, N'شهرکهنه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918200, N'باجگيران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918201, N'دولتخانه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918202, N'امامقلي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918301, N'خبوشان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918303, N'سنگر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918304, N'ينگي  قلعه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918305, N'شاه  جهان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918306, N'مايوان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918308, N'چري', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918901, N'نجف اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918902, N'پاکتل', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1918903, N'نرکوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1919000, N'برداسکن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1919100, N'مرکزي  برداسکن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1919101, N'کنارشهر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1919102, N'شهراباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1919103, N'کوهپايه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1919200, N'انابد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1919201, N'صحرا', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1919202, N'درونه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920000, N'کاشمر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920100, N'مرکزي  کاشمر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920101, N'بالاولايت -  مرکزي  کاشمر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920102, N'قلعه  بالا', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920103, N'کسرينه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920200, N'خليل  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920201, N'رستاق', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920203, N'ششطراز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920204, N'کندر -  خليل  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920300, N'کوهسرخ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920301, N'بررود', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920302, N'طرق', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920303, N'برکوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920304, N'ريوش', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920305, N'تکاب -  کوهسرخ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920306, N'اوندر', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920400, N'بردسکن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920901, N'زيرک اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920902, N'شفيع  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920903, N'ماراندنير', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920904, N'علي  ابادک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920905, N'قوژداباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1920906, N'مکي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921000, N'گناباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921100, N'مرکزي  گناباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921101, N'بيدخت', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921102, N'کاخک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921103, N'پس کلوت', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921104, N'بيمرغ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921105, N'حومه -  مرکزي  گناباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921106, N'بيلند', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921107, N'زبيد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921108, N'مرغش', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921200, N'بجستان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921201, N'مزار', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921202, N'جزين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921203, N'زين اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1921204, N'يونسي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1922101, N'بندان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1922102, N'معدن حاجات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1922103, N'ميغان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1922104, N'نه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1922105, N'خوانشرف', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1922202, N'دهک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1922901, N'گلنام', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923000, N'نيشابور', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923100, N'مرکزي  نيشابور', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923101, N'دربقاضي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923102, N'خونجان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923103, N'فضل', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923104, N'ابوسعيدي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923105, N'مازول', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923106, N'فطن اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923107, N'ريوند -  مرکزي  نيشابور', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923108, N'شادمهرک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923200, N'زبرخان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923201, N'دررود', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923202, N'قدمگاه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923203, N'اردوغش', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923204, N'ساحل  برج', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923205, N'اسحق  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923300, N'تخت جلگه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923301, N'بزغان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923303, N'طاغنکوه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923304, N'همت اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923305, N'فيروزه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923306, N'قاليباف', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923400, N'سرولايت', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923401, N'عبدالله  گيو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923402, N'بينالود', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923403, N'کلاته  محمدجان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923500, N'ميان جلگه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923501, N'بلهرات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923502, N'گلبوي  سفلي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923503, N'عشق  اباد -  ميان جلگه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923504, N'غزالي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923505, N'فديشه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923901, N'ساقي  بيک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1923902, N'خواجه  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999901, N'شهاباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999902, N'کوه  ميش', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999903, N'مهويد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999904, N'ميانکوهسارات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999905, N'شيخ  اميرانلو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999906, N'گرنک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999907, N'کهنه  فرود', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999908, N'مزدوران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999909, N'کرند', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999910, N'ماروسک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999911, N'قيس اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999912, N'لايلين نو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999913, N'قلعه  قصاب', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999914, N'قلعه  حاتم', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999915, N'قلجق', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999916, N'قصبه  شمالي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999917, N'قصبه  جنوبي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999918, N'علي  ابادقرني', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999919, N'گزخت', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999920, N'قرباشلو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999921, N'فندخت', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999922, N'فرطان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999923, N'نخودلي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999924, N'گلخندان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999925, N'محولات', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999926, N'طرجدد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999927, N'صيداباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999928, N'فتح  اباد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999929, N'شيرغان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999930, N'چولايي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999931, N'دارزون', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999932, N'حصارچه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999933, N'خرق', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999934, N'ريين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999935, N'دوين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999936, N'زمج', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999937, N'اوغاز', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999938, N'رود', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999939, N'شقان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999940, N'پيچرانلو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999941, N'رخ', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999942, N'ابشخانه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999943, N'درود', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999944, N'ده  محمد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999945, N'بارمعدن', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999946, N'دولويي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999947, N'ارومه', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999948, N'زيبد', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999949, N'جعفرابادسفلي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999950, N'جعفرابادعليا', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999951, N'سينا', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999952, N'اصفاک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999954, N'برک', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999955, N'برکال', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999957, N'اربقاين', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999958, N'چگينه  سفلي', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999959, N'ابکو', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999960, N'بصيران', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (1999961, N'نيگنان', N'خراسان رضوي', 19)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2000000, N'استان اصفهان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001000, N'اصفهان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001100, N'مرکزي  اصفهان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001101, N'خوراسگان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001102, N'رحنان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001103, N'براان جنوبي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001104, N'زيار', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001105, N'براان شمالي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001106, N'دستجاه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001107, N'جي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001108, N'ارغوانيه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001109, N'قهاب شمالي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001110, N'قهجاورستان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001111, N'قهاب جنوبي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001112, N'گورت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001113, N'محمودآباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001114, N'کرارج', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001115, N'دشتي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001116, N'ديدران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001200, N'بن رود', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001201, N'ورزنه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001202, N'گاوخوني', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001203, N'فورقان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001204, N'رودشت شرقي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001205, N'کفران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001300, N'جلگه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001301, N'هرند', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001302, N'اژيه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001303, N'امام  زاده  عبدالعزيز', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001304, N'رودشت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001400, N'کوهپايه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001401, N'تودشک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001402, N'جبل', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001403, N'جزه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001404, N'زفره', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001405, N'سيستان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001406, N'سجزي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001500, N'جرقويه  سفلي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001502, N'محمدآباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001503, N'جرقويه  وسطي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001600, N'جرقويه  عليا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001601, N'حسن آباد -  جرقويه  عليا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001602, N'رامشه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001901, N'حوزدان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001902, N'بهارانچي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001903, N'زمزه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001904, N'پزوه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001905, N'صيان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001906, N'باقرآباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001907, N'تورشکجو', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001908, N'جندابه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001909, N'افاران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001910, N'برزان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001911, N'بزوه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001912, N'کوجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001913, N'نيراباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001914, N'مهران دو', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001915, N'ناژوان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2001916, N'پيکان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002000, N'اردستان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002100, N'مرکزي  اردستان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002101, N'مهاباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002102, N'برزاوند', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002103, N'نيسيان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002104, N'همبرات', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002105, N'کچوسنگ', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002106, N'عليا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002107, N'بنم', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002108, N'کچو', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002109, N'کچومثغال', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002110, N'گرمسير', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002111, N'موغار', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002200, N'زواره', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002201, N'سفلي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002202, N'شهراب', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002203, N'ريگستان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002204, N'تلک اباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002901, N'چنار', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002902, N'صفي  اباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002903, N'سعيده', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002904, N'مهراباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2002905, N'تورزن', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003000, N'خميني  شهر', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003100, N'مرکزي  خميني  شهر', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003101, N'درچه  پياز', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003102, N'کوشک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003103, N'ماربين سفلي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003104, N'دستجردغداده', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003105, N'ماربين عليا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003106, N'ماربين وسطي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003107, N'قرطمان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003902, N'درنومغادران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003903, N'سيدان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003904, N'فروشان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003905, N'ورنوسفادران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2003906, N'فوزان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2004000, N'خوانسار', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2004100, N'مرکزي  خوانسار', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2004101, N'پشتکوه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2004102, N'ويست', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2004103, N'چشمه  سار', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2004104, N'قودجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2004105, N'کوهسار', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2004106, N'رحمت اباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005000, N'سميرم', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005100, N'مرکزي  سميرم', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005101, N'حنا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005102, N'وردشت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005103, N'فتح  اباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005104, N'ونک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005200, N'پادنا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005201, N'پادناسفلي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005202, N'چهارراه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005203, N'پادناعليا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005204, N'بيده', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005205, N'پادناوسطي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2005206, N'کمه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006000, N'فريدن', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006100, N'مرکزي  فريدن', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006101, N'داران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006102, N'دامنه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006103, N'دالانکوه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006104, N'ورزق', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006105, N'نهرخلج', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006106, N'زاينده  رودشمالي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006107, N'اسکندري', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006108, N'ورزق  جنوبي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006109, N'سفتجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006200, N'بويين ومياندشت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006201, N'افوس', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006202, N'سردسير', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006203, N'قره  بلطاق', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006204, N'کرچمبوشمالي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006205, N'کرچ', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006206, N'کرچمبوجنوبي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006207, N'بلطاق', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006208, N'گرجي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006209, N'ييلاق', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006210, N'ازناوله', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006300, N'چادکان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006301, N'چنارودجنوبي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006302, N'اورگان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006303, N'چنارودشمالي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006304, N'فراموشجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006305, N'کبوترسرخ', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006306, N'رزوه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006901, N'نيک اباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006902, N'نماگرد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2006903, N'خلعت پوشاد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007000, N'فريدونشهر', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007100, N'مرکزي  فريدونشهر', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007101, N'برف انبار', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007102, N'سنگباران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007103, N'پشتکوه  موگويي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007104, N'مصير', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007105, N'اسلام  ابادموگويي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007106, N'چشمه  لنگان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007107, N'سبيگ', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007108, N'عشاير', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007109, N'قلعه  سرخ', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007901, N'خرسانک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2007902, N'سروشگان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008000, N'فلاورجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008100, N'مرکزي  فلاورجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008101, N'کليشادوسورجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008102, N'قهدريجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008103, N'ابريشم', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008104, N'اشترجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008105, N'حسن آباد -  مرکزي  فلاورجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008106, N'زازران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008107, N'گلستان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008108, N'شرودان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008200, N'گرکن شمالي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008201, N'پيريکران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008202, N'سهروفيروزان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008901, N'سهرفروزان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2008902, N'افخد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009000, N'شهرضا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009100, N'مرکزي  شهرضا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009101, N'اسفرجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009102, N'منظريه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009103, N'عمرواباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009104, N'دشت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009105, N'مهيار', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009200, N'سميرم  سفلي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009201, N'دهاقان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009202, N'قمبوان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009203, N'همگين', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009204, N'موسي  اباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009205, N'کهرويه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009206, N'پوده', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009207, N'حيدراباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009901, N'اسفه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009902, N'بابوکان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2009903, N'ماران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010000, N'کاشان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010100, N'مرکزي  کاشان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010101, N'مياندشت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010102, N'مشگان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010103, N'کويرات', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010104, N'ابوزيداباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010106, N'استرک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010107, N'خرم  دشت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010108, N'کيچي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010200, N'اران وبيدگل', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010201, N'گل  ارا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010202, N'سفيددشت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010203, N'نصراباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010300, N'نياسر', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010301, N'برزک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010302, N'کوه  دشت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010303, N'ارمک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010400, N'قمصر', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010401, N'جوشقان قالي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010402, N'قهرود', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010901, N'راوند', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010902, N'اران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010903, N'طاهراباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010904, N'جوشقان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2010905, N'رازند', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011000, N'گلپايگان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011100, N'مرکزي  گلپايگان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011101, N'گوگد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011103, N'کنجدجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011104, N'نيوان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011105, N'نيوان نار', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011106, N'کناررودخانه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011107, N'سعيداباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011901, N'در', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011902, N'تيکن', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011903, N'اختخوان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011905, N'مرستانه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011906, N'مورچه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2011908, N'وانشان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012000, N'لنجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012100, N'مرکزي  لنجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012101, N'زرين شهر', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012102, N'سده  لنجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012103, N'ورنامخواست', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012104, N'چمگردان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012105, N'فولادشهر', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012107, N'خرم  رود', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012108, N'نوگوران -  مرکزي  لنجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012200, N'باغ  بهادران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012201, N'چرمهين', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012202, N'چم  رود', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012203, N'کرچکان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012204, N'زيرکوه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012205, N'کچوييه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012206, N'چم  کوه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012207, N'چم  يوسفعلي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012208, N'نوگوران -  باغ  بهادران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012901, N'اشيان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2012902, N'مورکان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013000, N'نايين', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013100, N'مرکزي  نايين', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013101, N'بافران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013102, N'بهارستان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013103, N'کجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013104, N'کوهستان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013105, N'بلان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013106, N'لاي  سياه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013107, N'همااباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013200, N'انارک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013201, N'چوپانان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013300, N'خوروبيابانک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013301, N'خور', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013302, N'جندق', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013303, N'بيابانک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013304, N'فرخي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013305, N'نخلستان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013306, N'مهرنجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013307, N'ايراج', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013901, N'عروسان کوره  گز', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013902, N'مهروران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013903, N'وادقان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013904, N'نيستانک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013905, N'مرق', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013906, N'محمدي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2013907, N'هندچوب', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014000, N'نجف اباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014100, N'مرکزي  نجف اباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014101, N'گلدشت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014102, N'جوزدان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014103, N'صادقيه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014104, N'حاجي آباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014105, N'صفاييه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014106, N'کهريزسنگ', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014200, N'تيران وکرون', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014201, N'تيران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014202, N'رضوانيه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014203, N'شهرک رضوان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014204, N'کرون عليا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014205, N'عسگران', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014206, N'کرون وسطي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014207, N'افجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014208, N'کرون سفلي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014209, N'ورپشت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014210, N'دونو', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014211, N'اسفيدواجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014300, N'مهردشت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014301, N'دهق', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014302, N'علويجه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014303, N'اشن', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014304, N'حسين آباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014901, N'اسفيدايان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2014902, N'دماب', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2015000, N'نطنز', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2015100, N'مرکزي  نطنز', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2015101, N'بادرود', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2015102, N'امام  زاده  اقاعلي  عباس', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2015103, N'اريسمان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2015104, N'برزرود', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2015105, N'هنجن', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2015106, N'کرکس', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2015107, N'طامه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2015108, N'طرق  رود', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2015109, N'طرق', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016000, N'برخواروميمه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016100, N'برخوارمرکزي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016101, N'دولت آباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016102, N'حبيب اباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016103, N'گز', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016104, N'دستگرد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016105, N'خورزوق', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016106, N'شاهين شهر', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016107, N'برخوارشرقي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016108, N'کمشجه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016109, N'برخوارغربي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016110, N'گرگاب', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016111, N'مورچه  خورت', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016112, N'لورديچه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016200, N'ميمه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016201, N'وزوان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016202, N'زرگان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016203, N'حسن رباط', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016204, N'ونداده', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016901, N'سين', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016902, N'کريکنه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016903, N'کرمکينه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2016904, N'خبر', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2017000, N'مبارکه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2017100, N'مرکزي  مبارکه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2017101, N'ديزجه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2017102, N'طالخونچه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2017103, N'گرکن جنوبي', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2017104, N'خولنجان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2017105, N'کرکوند', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2017901, N'بداغ  اباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099901, N'گروس', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099902, N'کوه  پا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099903, N'لالي  نيستانک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099904, N'لالي  مزيک', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099905, N'لالي  بلاداباد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099906, N'نجف', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099907, N'نصيروارود', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099908, N'دستجرد', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099909, N'چهارلنگ', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099910, N'حومه  علياشهرضا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099911, N'زواره  ريگستان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099912, N'حومه  سفلي  شهرضا', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099913, N'حومه  سفلي  نايين', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099914, N'حومه  عليانايين', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099915, N'بياضه', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099916, N'حومه  ورزق', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099917, N'رنان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099918, N'اوشيان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099919, N'ايدوعمش', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099921, N'ايرج', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099922, N'ذفره  سنجري', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2099923, N'لالي  سلطان', N'اصفهان', 20)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2100000, N'استان خراسان شمالي', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2101000, N'بجنورد', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2101100, N'مرکزي  بجنورد', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2101200, N'گرمخان', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2101201, N'حصارگرمخان', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2101300, N'رازوجرگلان', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2101301, N'راز', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2102000, N'جاجرم', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2102100, N'مرکزي  جاجرم', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2102101, N'گرمه  جاجرم', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2102102, N'درق', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2102200, N'جلگه  سنخواست', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2102201, N'سنخواست', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2102300, N'جلگه  شوقان', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2102301, N'شوقان', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2103000, N'اسفراين', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2103100, N'مرکزي  اسفراين', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2103200, N'بام  وصفي  اباد', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2103201, N'صفي  اباد', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2104000, N'فاروج', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2104100, N'مرکزي  فاروج', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2104102, N'تيتکانلو', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2105000, N'شيروان', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2105100, N'مرکزي  شيروان', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2105200, N'سرحد', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2105201, N'لوجلي', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2106000, N'مانه  وسملقان', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2106100, N'مرکزي  مانه  وسملقان', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2106101, N'اشخانه', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2106200, N'مانه', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2106201, N'پيش قلعه', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2106300, N'سملقان', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2106301, N'قاضي', N'خراسان شمالي ', 21)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2200000, N'استان کردستان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201000, N'سنندج', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201100, N'مرکزي  سنندج', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201102, N'حسين ابادجنوبي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201103, N'حسين آباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201104, N'حومه -  مرکزي  سنندج', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201105, N'صلوات اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201106, N'ابيدر', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201107, N'حسن آباد -  مرکزي  سنندج', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201108, N'نران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201109, N'علي آباد -  مرکزي  سنندج', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201110, N'ژاورودشرقي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201111, N'توريور', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201200, N'کلاترزان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201201, N'شويشه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201202, N'ژاورودغربي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201203, N'اويهنگ', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201204, N'نگل', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201901, N'چناران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201902, N'عباس اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201903, N'چهل  گزي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201904, N'امروله', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201905, N'سون', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201906, N'دولاب', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201907, N'داسيران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201908, N'ديرمولي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201909, N'سرقلعه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201910, N'ارندان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201911, N'سميران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201912, N'حلوان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201913, N'سهراب', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201914, N'دگايران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201915, N'ايذان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201916, N'باباويز', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201917, N'تازه  ابادتراگل', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201918, N'تازه  اباددويسه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201919, N'تازه  ابادسروالان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201920, N'تازه  ابادقراگول', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201921, N'سنگ سفيد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201922, N'شخنه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201923, N'شينه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201924, N'تخته', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201925, N'جبرييلان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201926, N'باينجفلو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201927, N'ترزه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201928, N'خانم  اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201930, N'برازان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201931, N'سيانار', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201932, N'افراسياب', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201933, N'سرپنبه  دول', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201934, N'بزلانه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201935, N'چرندو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201936, N'دملت اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201937, N'چکه  سفلي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201938, N'سرريز', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201939, N'نصرت اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201940, N'نوره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201941, N'گرجي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201942, N'گاواهنتو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201943, N'گرگرعليا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201944, N'نيدر', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201945, N'ياچکه  سفلي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201946, N'گران سفلي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201947, N'قراگول', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201948, N'قاديان دول', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201949, N'کوماين', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201950, N'نشور', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201951, N'مقريان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201952, N'کره  سني', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201953, N'ماچکه  عليا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201954, N'کاني  گلزار', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201955, N'مامق  نسعلي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201957, N'گيلانه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201958, N'قصريان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201959, N'هشيز', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201960, N'قراديان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201961, N'کيلانه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201962, N'گلين', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201963, N'کميز', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201964, N'لون', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201965, N'کانميشکان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201966, N'گزان سفلي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201968, N'گرماسن', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201969, N'بانيچوب', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201970, N'فقيه  سليمان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201971, N'ساکنه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201972, N'ذلکه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201973, N'تفتيله', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201974, N'دره  باغ', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201975, N'تنگي  سر', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201976, N'تودار', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201977, N'برزاب', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2201978, N'ترازوله', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202000, N'بانه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202100, N'مرکزي  بانه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202101, N'شوي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202200, N'الوت', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202201, N'پشت اربابا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202202, N'ارمرده', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202203, N'بله  که', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202300, N'نمشير', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202301, N'کوخان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202302, N'کاني  سور', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202303, N'بوالحسن', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202400, N'ننور', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202401, N'بويين', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202402, N'بويين سفلي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202901, N'قوليتر', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202902, N'گندمان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202903, N'سهدلو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202904, N'سرقول', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2202905, N'دارينه  عليا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203000, N'بيجار', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203100, N'مرکزي  بيجار', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203101, N'نجف اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203102, N'خورخوره -  مرکزي  بيجار', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203103, N'سيلتان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203104, N'توپ اغاج', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203105, N'حومه -  مرکزي  بيجار', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203106, N'چنگيزقلعه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203107, N'سياه  منصور', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203108, N'جعفرآباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203200, N'کراني', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203201, N'ياسوکند', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203202, N'طغامين', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203203, N'اغبلاغ  طغامين', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203204, N'گرگين', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203300, N'چنگ الماس', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203301, N'بابارشاني', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203302, N'پيرتاج', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203303, N'خسرواباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203901, N'خاندانقلي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203902, N'تازه  قشلاق', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203903, N'ميدان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203904, N'کورکوره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203905, N'قشلوقنرروز', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2203906, N'گراچقا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204000, N'سقز', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204100, N'مرکزي  سقز', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204101, N'ترجان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204102, N'قهرابادسفلي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204103, N'سرا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204104, N'تموغه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204105, N'ميرده', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204107, N'حسن سالاران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204200, N'زيويه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204201, N'تيلکوه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204202, N'خورخوره -  زيويه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204203, N'امام', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204204, N'سنته', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204205, N'گل  تپه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204206, N'صاحب', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204901, N'دربنده', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204902, N'کاني  کوچک', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204904, N'نير', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204905, N'مشميز', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204906, N'ميرکي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204907, N'خليچيان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204908, N'کله  کان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204909, N'احمد آباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204910, N'خانه  يران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204911, N'اکتون سفلي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204912, N'گلزي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204913, N'کهريزه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204914, N'کلچنه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204915, N'کريم  اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204916, N'کاني  کبود', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204917, N'کنده  سوزه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204918, N'کاکه  سياو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204919, N'گلزاربالا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204920, N'قلعه  ني', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204921, N'قلعه  کهنه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204922, N'قتلو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204923, N'قپلانتو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204924, N'نوراباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204925, N'کندولان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204926, N'بلوز', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204927, N'پيريولن', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204928, N'سيمرغ', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204929, N'اسلام آباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204931, N'سرچشمه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2204932, N'زيارت عليا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205000, N'ديواندره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205100, N'مرکزي  ديواندره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205101, N'حسين ابادشمالي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205102, N'خرکه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205103, N'چهل  چشمه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205104, N'شريف اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205105, N'سارال', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205106, N'هزارکانيان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205107, N'کوله', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205108, N'حومه -  مرکزي  ديواندره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205109, N'نساره  عليا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205110, N'قراتوره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205111, N'گاوشله', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205200, N'کرفتو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205201, N'اوباتو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205202, N'گورباباعلي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205203, N'کاني  شيرين', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205204, N'شالي  شل', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205205, N'زرينه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2205901, N'شاه  ولي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206000, N'قروه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206100, N'مرکزي  قروه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206101, N'سريش اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206102, N'پنجه  علي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206103, N'کاني  گنجي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206104, N'دلبران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206105, N'بدر', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206106, N'قلعه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206107, N'لک', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206108, N'گيلکلو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206109, N'قصلان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206110, N'چهاردولي  غربي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206111, N'ذرج', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206112, N'چهاردولي  شرقي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206113, N'وينسار', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206114, N'پنجه  علي  جنوبي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206115, N'قاملو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206200, N'ييلاق', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206201, N'دهگلان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206202, N'ييلاق  شمالي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206203, N'بله  دستي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206204, N'ييلاق  جنوبي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206205, N'بلبان اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206206, N'حومه  دهگلان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206207, N'حسن آباد -  ييلاق', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206208, N'قوري  چاي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206901, N'زاغه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206902, N'شالوزه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206903, N'سيرکي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206904, N'سراسبوره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206905, N'دروديان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206906, N'سرواله', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206907, N'باغچه  مريم', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206908, N'ژان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206909, N'بهمن اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206910, N'سيس', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206911, N'چراغ  اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206912, N'چرخه  بيان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206913, N'علي آباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206914, N'چقاقدره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206915, N'چقي  قدره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206916, N'کبودفاني  عليا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206917, N'نارنجک', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206918, N'کاني  پان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206919, N'گزگزاره  عليا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206920, N'قلعه  فولاد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206921, N'هليزاباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206923, N'ميانگروراده', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206924, N'قروپاي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206925, N'الي  پنيک', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2206926, N'شهاب الدين', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207000, N'مريوان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207100, N'مرکزي  مريوان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207101, N'زريوار', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207102, N'ني', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207103, N'سرگل', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207104, N'کاني  دينار', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207105, N'کوماسي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207106, N'پيرخضران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207200, N'خاووميراباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207201, N'برده  رشه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207300, N'سرشيو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207301, N'چناره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207302, N'گلچيدر', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207303, N'جانوره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207400, N'سرواباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207401, N'اورامان تخت', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207402, N'پايگلان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207403, N'رزاب', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207404, N'بيساران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207405, N'ژريژه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207406, N'قلعه  جي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207407, N'کوسالان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207901, N'ميراباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207902, N'هوير', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207904, N'ولرژبر', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207905, N'گويله', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207906, N'گيلي  کران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207907, N'شهراورامان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207908, N'چويين', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207909, N'دره  ويان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207910, N'حسن اوله', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207911, N'بوريدر', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207912, N'سرومال', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207914, N'سپيران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207915, N'بياران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207916, N'خانقاه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207917, N'دانيکش', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207918, N'ترخان اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207919, N'تودارملا', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207920, N'سيور', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207921, N'بباران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207922, N'سرخه  توت', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207923, N'داميردن', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207924, N'ادينگ', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207925, N'بروده', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2207926, N'اوپهنگ', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208000, N'کامياران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208100, N'مرکزي  کامياران', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208101, N'بيلوار', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208102, N'شيروانه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208103, N'شاهو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208104, N'ورمهنگ', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208105, N'ژاورود', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208106, N'گشکي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208200, N'موچش', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208201, N'اميرآباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208203, N'عوالان', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208204, N'نشورسفلي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208205, N'گاورود', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208206, N'کوله  ساره', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208207, N'سورسور', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2208208, N'يوسف اباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299901, N'گاوبازه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299902, N'گورک نرخر', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299903, N'ميرانشاه', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299904, N'خاززميراباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299905, N'بهارلو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299906, N'خاو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299907, N'اوردغربي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299908, N'دشت طال', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299909, N'اورودشرقي', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299910, N'رشه  ده', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299911, N'اسفندآباد', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299912, N'تيژتيژ', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299913, N'سبدلو', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299914, N'چالي  سور', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2299915, N'گروس', N'کردستان', 22)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2300000, N'استان هرمزگان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301000, N'بندرعباس', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301100, N'مرکزي  بندرعباس', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301101, N'گچين', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301102, N'گچين بالا', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301103, N'ايسين', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301104, N'محله  نوايسين', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301105, N'تازيان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301106, N'تازيان پايين', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301107, N'تخت', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301108, N'قلعه  قاضي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301109, N'شميل', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301200, N'خمير', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301201, N'بندرخمير', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301202, N'پل  شرقي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301203, N'کهورستان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301204, N'رويدر', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301300, N'فين', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301301, N'سياهو', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301302, N'گهره', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301303, N'قطب اباد', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2301901, N'ارتوجان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302000, N'بندرلنگه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302100, N'مرکزي  بندرلنگه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302101, N'کنگ', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302102, N'حومه -  مرکزي  بندرلنگه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302103, N'گزير', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302104, N'مغويه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302105, N'بندرمغويه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302106, N'مهران', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302107, N'بدل', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302108, N'دژگان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302200, N'بستک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302201, N'ده  تل', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302202, N'فرامرزان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302203, N'کمشک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302204, N'فتويه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302205, N'گوده', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302206, N'دهنگ', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302207, N'هرنگ', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302208, N'جناح', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302300, N'شبيکوه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302301, N'چارک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302302, N'بندرچارک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302303, N'مقام', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302304, N'بندرمقام', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302400, N'کيش', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302401, N'جزيره  کيش', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302402, N'لاوان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302403, N'جزيره  لاوان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302500, N'گاوبندي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302501, N'بهدشت', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302502, N'دشتي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302503, N'مهرگان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302504, N'به  ده', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2302505, N'کوشکنار', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2303000, N'ابوموسي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2303100, N'مرکزي  ابوموسي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2303101, N'سيري', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2303102, N'جزيره  سيري', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2303200, N'تنب', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2303201, N'جزيره  تنب بزرگ', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304000, N'جاسک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304100, N'مرکزي  جاسک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304101, N'بندرجاسک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304102, N'جاسک کهنه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304103, N'سورک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304104, N'ليردف', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304105, N'کنگان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304106, N'گابريک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304107, N'يکدار', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304200, N'بشاگرد', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304201, N'سردشت', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304202, N'جکدان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304203, N'کلورجکدان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304204, N'گافروپارمون', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304205, N'درنگ مدو', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2304206, N'انگهران', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2305000, N'حاجي آباد', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2305100, N'مرکزي  حاجي  اباد', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2305101, N'درگاه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2305102, N'دهستان بالا', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2305103, N'طارم', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2305104, N'پتکوييه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2305200, N'فارغان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2305202, N'احمدي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2305203, N'سرگز', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306000, N'رودان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306100, N'مرکزي  رودان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306101, N'دهبارز', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306102, N'اب نما', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306103, N'خراجي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306104, N'فارياب -  مرکزي  رودان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306105, N'بيکاه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306106, N'راهدار', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306107, N'جغين شمالي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306108, N'بالاشهر', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306109, N'جغين جنوبي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306110, N'پالور', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306200, N'رودخانه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306201, N'زيارتعلي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306202, N'مسافراباد', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306203, N'نوراباد', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306204, N'رودخانه  بر', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2306205, N'فارياب -  رودخانه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307000, N'قشم', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307100, N'مرکزي  قشم', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307101, N'هرمز', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307102, N'حومه -  مرکزي  قشم', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307103, N'درگهان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307104, N'رمکان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307200, N'شهاب', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307201, N'سوزا', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307202, N'دولاب', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307203, N'صلخ', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307204, N'طبل', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307205, N'لارک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307206, N'جزيره  لارک شهري', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307207, N'هنگام', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2307208, N'جزيره  هنگام', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308000, N'ميناب', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308100, N'مرکزي  ميناب', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308101, N'گوربند', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308102, N'حومه -  مرکزي  ميناب', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308103, N'حکمي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308104, N'بندزرک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308105, N'تياب', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308106, N'کريان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308107, N'توکهور', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308108, N'هشت بندي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308200, N'بيابان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308201, N'سيريک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308202, N'بماني', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308203, N'کوهستک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308204, N'گونمردي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308300, N'سندرک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308301, N'بندر', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2308302, N'درپهن', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399901, N'ماشه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399902, N'مزروقي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399903, N'هندورابي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399904, N'لمزان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399905, N'کردر', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399906, N'دگان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399907, N'بندرگنگ', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399908, N'سعادت اباد', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399909, N'بهمدي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399910, N'عبيدلي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399911, N'فروربزرگ', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399912, N'شتوار', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399913, N'الحرم', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399914, N'شيبکوه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399916, N'پي  وشک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399917, N'دراگاه', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399918, N'بادافشان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399919, N'رودان احمدي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399920, N'فرورکوچک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399921, N'تنب کوچک', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399922, N'سري', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399923, N'غربي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399924, N'شرقي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399925, N'بدوي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399926, N'حمادي', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2399927, N'پارسيان', N'هرمزگان', 23)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2400000, N'استان همدان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401000, N'همدان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401100, N'مرکزي  همدان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401101, N'مريانج', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401102, N'گنبد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401103, N'الوندکوه  شرقي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401104, N'تفريجان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401105, N'الوندکوه  غربي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401106, N'انصارالامام', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401107, N'سنگستان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401108, N'ابشينه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401109, N'هگمتانه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401110, N'جورقان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401111, N'ابرو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401112, N'مزدقينه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401200, N'شرا', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401201, N'جيحون دشت', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401202, N'قهاوند', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401203, N'چاه  دشت', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401204, N'بيوک اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401205, N'شوردشت', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401206, N'کورزه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401207, N'عبدالرحيم', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401300, N'فامنين', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401301, N'پيشخور', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401302, N'تجرک', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401303, N'مفتح', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401304, N'اصله', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401305, N'خرم  دشت', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401306, N'نيکچه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401901, N'قورليچه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401902, N'مسلم  اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401903, N'ارزانقود', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401904, N'قاسم  اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401905, N'سرخ  اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401906, N'امزاجرد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401907, N'بهمن اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401908, N'حصارديزج', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401909, N'دره  مرادبيک', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401910, N'انراجرد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2401911, N'جهاداباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402000, N'اسداباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402100, N'مرکزي  اسداباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402101, N'چهاردولي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402102, N'چنارعليا', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402103, N'سيدجماالدين', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402104, N'جنت اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402105, N'دربندرود', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402106, N'يوسف اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402107, N'پيرسليمان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402108, N'اجين', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402109, N'جلگه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402110, N'موسي  اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402111, N'کليايي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402112, N'طويلان سفلي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402901, N'خاکريز', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2402903, N'هلبرسفلي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403000, N'بهار', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403100, N'مرکزي  بهار', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403101, N'صالح  اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403102, N'سيمينه  رود', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403103, N'ابرومند', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403104, N'ديمکاران', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403105, N'حسن قشلاق', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403106, N'طاهرلو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403107, N'چاپان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403108, N'قشلاق', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403200, N'لالجين', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403201, N'سفالگران', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403202, N'ديناراباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403203, N'مهاجران', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403204, N'حسين ابادلتگاه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2403901, N'گندجين', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404000, N'تويسرکان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404100, N'مرکزي  تويسرکان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404101, N'سرکان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404102, N'کزان رود', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404103, N'باباپير', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404104, N'خرم  رود', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404105, N'اشتران', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404106, N'حيقوق  نبي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404107, N'جعفريه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404108, N'سيدشهاب', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404200, N'قلقل  رود', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404201, N'فرسفج', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404202, N'ميان رود', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404203, N'والاشجرد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404204, N'کمال  رود', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404205, N'ميانده', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404901, N'عين اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404902, N'قلعه  اس جان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404903, N'باباکمال', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404904, N'سيستانه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2404905, N'گاوکران', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405000, N'رزن', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405100, N'مرکزي  رزن', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405101, N'خرقان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405102, N'سورتجين', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405200, N'سردرود', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405201, N'سردرودعليا', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405202, N'خورونده', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405203, N'سردرودسفلي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405204, N'دمق', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405205, N'بغراطي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405206, N'بابانظر', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405300, N'قروه  درجزين', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405301, N'درجزين عليا', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405302, N'چانکرين', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405303, N'درجزين سفلي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405304, N'درجزين', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405305, N'نارمجک', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405306, N'کرمس', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405307, N'کهارد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405901, N'گچيلو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405902, N'سيراب', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405903, N'قلعه  جوق', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405904, N'سايان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405905, N'قروه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405906, N'عمان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405907, N'زندليج', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405908, N'شوند', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405909, N'خيراباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2405910, N'فارسجين', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406000, N'کبودراهنگ', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406100, N'مرکزي  کبودراهنگ', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406101, N'راهب', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406102, N'دستجرد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406103, N'حاجيلو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406104, N'داق  داق  اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406105, N'سبزدشت', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406106, N'ويان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406107, N'شيرين سو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406108, N'مهربان عليا', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406109, N'چالو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406110, N'کوهين', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406200, N'گل  تپه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406201, N'علي  صدر', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406202, N'مهربان سفلي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406203, N'قهوردسفلي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406901, N'قرخ  بلاغ', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406902, N'کوريجان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2406904, N'شاره', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407000, N'ملاير', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407100, N'مرکزي  ملاير', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407101, N'حرم  رودعليا', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407102, N'مهراباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407103, N'موزاران', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407104, N'جوراب', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407105, N'کمازان سفلي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407106, N'مهدويه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407107, N'جوزان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407108, N'کمازان وسطي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407109, N'پيروز', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407110, N'کوه  سرده', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407111, N'ازناو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407112, N'کمازان عليا', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407113, N'زنگنه  عليا', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407200, N'جوکار', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407201, N'ترک غربي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407202, N'ينکي  کند', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407203, N'ترک شرقي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407204, N'اسلام آباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407205, N'المهدي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407206, N'حسين ابادشاملو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407300, N'سامن', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407301, N'کهکدان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407302, N'سفيدکوه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407303, N'انوج', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407304, N'اورزمان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407305, N'حرم  رودسفلي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407306, N'حسين ابادناظم', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407901, N'اردکلر', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407902, N'امام  زاده  خاتون', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407903, N'طايمه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407904, N'قلعه  نو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407905, N'بيدکرپه  سفلي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407906, N'پاتپه', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2407907, N'نيکي  کند', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408000, N'نهاوند', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408100, N'مرکزي  نهاوند', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408101, N'گاماسياب', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408102, N'باباقاسم', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408103, N'شعبان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408104, N'کوهاني', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408105, N'طريق  الاسلام', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408106, N'دهفول', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408107, N'فضل', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408108, N'برزول', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408109, N'گيان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408200, N'خزل', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408201, N'فيروزان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408202, N'خزل  شرقي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408203, N'سلکي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408204, N'شهرک', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408901, N'کاحيدر', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408902, N'گوشه  بديع  الزمان', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2408903, N'کفراج', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2499901, N'فارسينج', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2499902, N'سرابي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2499903, N'شاملو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2499904, N'سفلي', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2499905, N'عليا', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2499906, N'حسام  اباد', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2499907, N'کرزانرود', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2499908, N'وفس عاشقلو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2499911, N'خدابنده  لو', N'همدان', 24)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2500000, N'استان چهارمحال  بختياري', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501000, N'شهرکرد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501100, N'مرکزي  شهرکرد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501101, N'سورشجان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501102, N'کيان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501103, N'سامان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501104, N'فرخ  شهر', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501105, N'هفشجان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501106, N'شوراب صغير', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501107, N'هوره', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501108, N'طاقانک', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501109, N'حومه -  مرکزي  شهرکرد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501110, N'چالشتر', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501111, N'لار', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501112, N'هاروني', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501113, N'احمد آباد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501200, N'بن', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501201, N'وردنجان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501202, N'زاينده  رودجنوبي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501203, N'حيدري', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501300, N'کيار', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501301, N'شلمزار', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501302, N'کيارغربي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501303, N'کيارشرقي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501304, N'شهرک عدل', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501901, N'فرح  شهر', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501902, N'سرتشنيز', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501903, N'پيربلوط', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501904, N'خيراباد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501905, N'سروشجان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501906, N'قلعه  تک', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501907, N'گهرو', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501908, N'کرسنک', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501909, N'يان چشمه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501910, N'کاه  کش', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2501911, N'هرچگان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502000, N'اردل', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502100, N'مرکزي  اردل', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502101, N'ناغان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502102, N'پشتکوه -  مرکزي  اردل', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502103, N'رستم  اباد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502104, N'ديناران', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502105, N'ليرابي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502200, N'ميانکوه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502201, N'ده  کهنه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502202, N'مشايخ', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502203, N'دوپلان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502204, N'شليل', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502205, N'شکراباد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2502901, N'کهنه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2503000, N'بروجن', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2503100, N'مرکزي  بروجن', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2503101, N'فرادنبه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2503102, N'حومه -  مرکزي  بروجن', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2503103, N'نقنه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2503200, N'گندمان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2503201, N'بلداجي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2503202, N'چغاخور', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2503203, N'اورگان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2503901, N'دورهون', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504000, N'فارسان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504100, N'مرکزي  فارسان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504101, N'جونقان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504102, N'باباحيدر', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504103, N'ميزدج  عليا', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504104, N'فيل  اباد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504105, N'ميزدج  سفلي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504106, N'چليچه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504200, N'کوهرنگ', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504201, N'شوراب تنگزي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504202, N'چلگرد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504203, N'ميانکوه  موگوني', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504204, N'خويه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504205, N'دشت زرين', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504206, N'صالح  اباددشت زري', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504300, N'بازفت', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504301, N'چمن گلي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504302, N'دواب', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504303, N'صمصامي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504901, N'کارکنان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504902, N'پبدني', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504903, N'پردنجان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504904, N'ده  چشمه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504905, N'گوجان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2504906, N'شوراب', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505000, N'لردگان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505100, N'مرکزي  لردگان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505101, N'بارز', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505102, N'قلعه  مدرسه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505103, N'ريگ', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505104, N'کلار', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505105, N'سردشت', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505106, N'منج', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505107, N'منج  برافتاب', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505108, N'ميلاس', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505109, N'گوشه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505200, N'خانميرزا', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505201, N'الوني', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505202, N'ارمند', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505203, N'ارمندعليا', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505300, N'فلارد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505301, N'مال  خليفه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505302, N'پشتکوه -  فلارد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505303, N'دره  نامدار', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505901, N'سيني', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505902, N'چيگر', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505903, N'شش بهره  عليا', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505904, N'شهيدان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505905, N'دره  رزگاه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505906, N'دودرا', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505907, N'طلايه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505908, N'ساطح', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505909, N'زرين دره', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505910, N'شاه  نجف', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505911, N'پيران', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505912, N'دومکان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505913, N'باغنار', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505914, N'اقايي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505915, N'چالپکان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505916, N'چله  گاه', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505917, N'کلامريي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2505918, N'مسن', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2599901, N'قهفرج', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2599902, N'دستگرد', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2599903, N'بيرگان', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2599904, N'تنگ گزي', N'چهارمحال  بختياري', 25)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2600000, N'استان لرستان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601000, N'خرم آباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601100, N'مرکزي  خرم  اباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601102, N'ايمان اياد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601103, N'رباط', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601104, N'رباطنمکي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601105, N'کرگاه  غربي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601106, N'بدرابادسفلي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601107, N'ده  پير', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601108, N'کمالوندغلامطي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601109, N'ده  پيرشمالي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601110, N'تجرسراب', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601111, N'کاکاشرف', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601112, N'برافتاب دو', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601113, N'کرگاه  شرقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601114, N'دارايي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601200, N'پاپي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601201, N'کشور', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601202, N'حکومتي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601204, N'چم  سنگر', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601205, N'تنگ هفت', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601206, N'گريت', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601207, N'سراب جلدان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601208, N'سرکانه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601209, N'تازان کشور', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601210, N'سپيددشت', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601300, N'چغلوندي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601301, N'بيرانوندشمالي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601302, N'خراشکفت', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601303, N'بيرانوندجنوبي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601304, N'چهاربرجي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601400, N'دوره  چگني', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601401, N'دوره', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601402, N'سراب دوره', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601403, N'کشکان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601404, N'چم  پلک', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601405, N'تشکن', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601406, N'چاه  ذوالفقار', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601407, N'ميش کر', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601500, N'زاغه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601501, N'قايدرحمت', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601502, N'سياه  گوشي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601503, N'رازان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601600, N'ويسيان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601601, N'گدارمحمودوند', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601602, N'شوراب', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601603, N'شوراب سفلي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2601901, N'قلعه  شرجنگ', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602000, N'سلسله', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602100, N'مرکزي  سلسله', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602101, N'الشتر', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602102, N'يوسف وند', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602103, N'ده  رحيم', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602104, N'هنام', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602105, N'سياه  پوش', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602106, N'دواب', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602107, N'مومن اباد -  مرکزي  سلسله', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602108, N'قلعه  مظفري', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602109, N'چشمه  برقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602200, N'فيروزاباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602201, N'قلايي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2602202, N'عدل  اباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603000, N'پلدختر', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603100, N'مرکزي  پلدختر', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603101, N'ملاوي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603102, N'موراني', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603103, N'جايدر', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603104, N'سراب حمام', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603105, N'جلوگير', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603106, N'پل  تنگ پاعلم', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603107, N'ميانکوه  غربي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603108, N'واشيان نصيرتپه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603200, N'معمولان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603201, N'افرينه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603202, N'ميانکوه  شرقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2603203, N'چشمک زيرتنگ', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604000, N'اليگودرز', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604100, N'مرکزي  اليگودرز', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604101, N'بربرودشرقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604102, N'چمن سلطان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604103, N'بربرودغربي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604104, N'شاپوراباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604105, N'پاچه  لک شرقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604106, N'سور', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604107, N'خمه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604108, N'خمه  سفلي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604109, N'فرسش', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604200, N'بشارت', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604201, N'پيشکوه  ذلقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604202, N'کيزاندوه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604203, N'ذلقي  غربي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604204, N'پرچل', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604205, N'ذلقي  شرقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604206, N'بزنويد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604300, N'ززوماهرو', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604301, N'ززشرقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604302, N'شول  ابادسفلي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604303, N'ززغربي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604304, N'حيه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604305, N'ماهرو', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604306, N'برگسر', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604901, N'انوج', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604902, N'حومه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604903, N'ايونده', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604904, N'دولت آباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604905, N'ده  نصير', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604906, N'ززم', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604907, N'ده  سفير', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2604908, N'رزم', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605000, N'ازنا', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605100, N'مرکزي  ازنا', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605101, N'پاچه  لک غربي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605102, N'المهدي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605103, N'سيلاخورشرقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605104, N'دربند', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605200, N'جاپلق', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605201, N'جاپلق  غربي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605202, N'اشوراباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605203, N'جاپلق  شرقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605204, N'مومن اباد -  جاپلق', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605205, N'سيوله', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2605901, N'بيدستان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606000, N'بروجرد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606100, N'مرکزي  بروجرد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606101, N'والانجرد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606102, N'همت اباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606103, N'مرکزخدمات همت اباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606104, N'دره  صيدي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606105, N'شيروان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606106, N'مرکزکشاورزي  شيروان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606200, N'اشترينان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606201, N'دره  گرگ', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606202, N'بردسره', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606203, N'جعفرآباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606204, N'گودرزي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606205, N'بن ديزه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606206, N'ملمي  جان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606207, N'گوشکي  سفلي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606208, N'کوشکي  عليا', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606209, N'کمره  بالا', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606210, N'گندل  کيلان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606211, N'چهاريره', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606212, N'ده  نوشاقلي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606213, N'ده  ترکان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606214, N'توده  زن', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606216, N'برکت اباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606901, N'وليان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606902, N'دهگاه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606903, N'گوشه  محسنعلي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606904, N'گوشه  گاپله', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606905, N'وزيراباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606906, N'ميري  سادات', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606907, N'دره  زاغه  بالا', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606908, N'بلوطبيک', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606909, N'ده  شيخان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606910, N'کتچينه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606911, N'سرنجه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606912, N'قلعه  نوشوکتي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606913, N'سرمستي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606915, N'کريم  ابادکوله', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606916, N'پهلوانکل', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606917, N'کبوترلان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606918, N'تپه  ملا', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606919, N'قشلاق', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606920, N'فتح  اباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606921, N'فلاندشت', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606922, N'سرفجه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606923, N'اشتان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606924, N'زميه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606925, N'دهنو', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606926, N'جهان اباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606927, N'چبدر', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606928, N'فيال', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606929, N'زارم', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606930, N'گوشه  چهارچنار', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606931, N'اسدخاني', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2606932, N'هيراب', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607000, N'دلفان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607100, N'مرکزي  دلفان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607101, N'نوراباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607102, N'ظفراباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607103, N'ميربگ شمالي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607104, N'فرهاداباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607105, N'ميربگ جنوبي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607106, N'دم  باغ', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607107, N'خاوه  شمالي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607108, N'کفراج', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607109, N'خاوه  جنوبي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607110, N'نورعلي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607111, N'فروزوندوسطي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607200, N'کاکاوند', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607201, N'کاکاوندشرقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607202, N'هفت چشمه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607203, N'کاکاوندغربي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607204, N'چشمه  کوزان عليا', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607205, N'ايتيوندجنوبي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607206, N'کهريزوردشت عليا', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2607207, N'ايتيوندشمالي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608000, N'دورود', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608100, N'مرکزي  دورود', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608101, N'سياه  کله', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608102, N'ژان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608103, N'حشمت اباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608200, N'سيلاخور', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608201, N'کاغه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608202, N'چالانچولان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608901, N'حاجي آباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608902, N'احمد آباد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608903, N'سياه  ول', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608904, N'بياتان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608905, N'درگران عليا', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608906, N'سوران', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608907, N'ميدان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608908, N'يزدجرد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2608909, N'خان وردي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609000, N'کوهدشت', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609100, N'مرکزي  کوهدشت', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609101, N'کوهدشت جنوبي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609102, N'خوشناب وند', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609103, N'کوهدشت شمالي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609104, N'نامجو', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609105, N'گل  گل', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609106, N'اشتره  گل  گل', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609200, N'رومشکان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609201, N'رومشکان شرقي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609202, N'چقابل', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609203, N'رومشکان غربي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609204, N'سوري', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609300, N'طرهان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609301, N'گراب', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609302, N'درب گنبد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609400, N'کوناني', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609401, N'زيرتنگ', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609402, N'گرخوشاب عبدي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609901, N'کتول', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609902, N'سيرم', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609903, N'برشنودي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2609904, N'گل  سرخ', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699902, N'سراب نرم', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699903, N'حسينيه  عليا', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699905, N'دالوند', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699906, N'ريمله', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699907, N'دواب اشتر', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699908, N'ايوتي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699909, N'ابسرده', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699910, N'ابستان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699911, N'خاوه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699912, N'سفيددشت', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699913, N'بسطام', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699914, N'چگني', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699915, N'خيلوندي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699916, N'گازه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699917, N'منکره', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699918, N'کرکي', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699919, N'هرو', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699920, N'کريت', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699921, N'مال  اسد', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699922, N'ناوکش', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699923, N'ماسور', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699924, N'مازو', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699925, N'وند', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699926, N'هويان', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699927, N'ورکوه', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699928, N'ميرزاوند', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2699929, N'مامون', N'لرستان', 26)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2700000, N'استان ايلام', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2701000, N'ايلام', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2701100, N'مرکزي  ايلام', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2701101, N'ميش خاص', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2701102, N'جعفرآباد', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2701103, N'ده  پايين', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2701104, N'چالسرا', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2701200, N'چوار', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2701201, N'ارکوازي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2701202, N'مورت', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2701203, N'بولي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2701204, N'گنجوان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2702000, N'ايوان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2702100, N'مرکزي  ايوان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2702101, N'سراب', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2702102, N'نبوت', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2702200, N'زرنه', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2702201, N'کلان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2702202, N'ترن', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2702901, N'گلان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703000, N'دره  شهر', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703100, N'مرکزي  دره  شهر', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703101, N'ارمو', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703102, N'ماژين', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703103, N'ماژين مرکزي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703104, N'زريندشت', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703105, N'دشت ابادعليا', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703200, N'بدره', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703201, N'دوستان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703202, N'وليعصر', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703203, N'هندميني', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703204, N'چشمه  شيرين', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2703205, N'چشمه  ماهي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2704000, N'ابدانان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2704100, N'مرکزي  ابدانان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2704101, N'چم  کبود', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2704102, N'هزاراني', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2704103, N'ماسبي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2704104, N'انجيره', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2704200, N'سراب باغ', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2704201, N'مورموري', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705000, N'دهلران', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705100, N'مرکزي  دهلران', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705101, N'اناران', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705102, N'بيشه  دراز', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705200, N'زرين اباد', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705201, N'ميمه', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705202, N'پهله', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705203, N'سيدابراهيم', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705204, N'بردي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705205, N'سيدناصرالدين', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705300, N'موسيان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705301, N'نهرعنبر', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705302, N'بربيجه', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705303, N'دشت عباس', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2705304, N'ابوغوير', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706000, N'شيروان وچرداول', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706100, N'مرکزي  شيروان وچرداول', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706101, N'سرابله', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706102, N'شباب', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706103, N'اسمان اباد', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706104, N'صيدنظري  سفلي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706200, N'هليلان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706201, N'کهره', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706202, N'بيجنوند', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706203, N'بلاوه  تره  سفلي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706204, N'زردلان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706205, N'پيازاباد', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706300, N'شيروان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706301, N'لومار', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706302, N'کارزان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706303, N'چشمه  پهن', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706304, N'زنگوان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2706305, N'سرتنگ مله  ماران', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707000, N'مهران', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707100, N'مرکزي  مهران', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707101, N'محسن اباد', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707102, N'اسلاميه', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707200, N'ارگوازي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707201, N'قلعه  دره  ملکشاهي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707202, N'گچي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707203, N'مهر', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707204, N'چمزي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707205, N'گنبدپيرمحمد', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707206, N'شوهان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707207, N'دول  کبودخوشادول', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707300, N'صالح  اباد', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707301, N'هجداندشت', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707302, N'ريکا', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707901, N'ارکوازملکشاهي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2707902, N'وري', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799901, N'مايسني', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799902, N'ماين', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799903, N'نصيريان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799904, N'يوسف اباد', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799905, N'سرابي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799907, N'خالصه', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799908, N'زرگوش', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799909, N'شاه  کرمي', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799910, N'درود', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799911, N'عليشروان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799912, N'زرداب', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799914, N'ابهربالا', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799915, N'خرسان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799916, N'سادات', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799917, N'بجوند', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799918, N'جوي  زرايوان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799919, N'خربزان', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2799920, N'چرداول', N'ايلام', 27)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2800000, N'استان کهکيلويه  وبويراح', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801000, N'بويراحمد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801100, N'مرکزي  بويراحمد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801101, N'ياسوج', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801102, N'سررودشمالي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801103, N'مادوان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801104, N'سررودجنوبي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801105, N'تل  خسرو', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801106, N'دشت روم', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801108, N'سپيدار', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801109, N'کاکان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801110, N'عباسعلي  خاني', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801111, N'رودبال', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801200, N'دروهان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801201, N'سي  سخت', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801202, N'دنا', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801203, N'کريک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801204, N'پاتاوه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801205, N'سادات محمودي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801206, N'دژک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801207, N'کبکيان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801208, N'چيتاب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801300, N'مارگون', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801301, N'زيلايي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801302, N'ماشمي  سفلي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801400, N'لوداب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801401, N'گراب سفلي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801402, N'چين', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801403, N'ظفرتهلايي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801500, N'سيسخت', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801901, N'دشمن زياري  جنوبي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801905, N'کلات', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801906, N'شيخ  سرکه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801907, N'حسين آباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801908, N'چنارستان سفلي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801909, N'زنگورسفلي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801910, N'قلعه  دپستي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801911, N'بي  منجگان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801912, N'بن دره', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801913, N'شهنيز', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801914, N'دلي  گردوعليا', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801915, N'دم  چنار', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801916, N'دهکرافتاب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801917, N'چنار', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801918, N'علي آباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801919, N'چمن', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801920, N'عزيزي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801921, N'جهان اباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801922, N'زنگورعليا', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801923, N'دارشاهي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801925, N'هادي  اباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2801926, N'نيمه  ور', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802000, N'کهکيلويه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802100, N'مرکزي  کهکيلويه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802101, N'دهدشت', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802103, N'دهدشت شرقي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802104, N'ضرغام  اباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802105, N'دهدشت غربي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802106, N'سرمور', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802107, N'پشته  ذيلايي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802108, N'سواري', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802109, N'طيبي  گرمسيري  جنوبي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802110, N'دشمن زياري', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802111, N'قلعه  دختر', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802112, N'کفش کنان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802113, N'راک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802114, N'جعل', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802115, N'ارند', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802116, N'سرخلوابول  خبر', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802117, N'بردراسون', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802119, N'بهرم  مرغابي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802123, N'برم  مرخاني', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802124, N'بيمنجگان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802125, N'چاه  بردي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802126, N'شيرازي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802127, N'دمعباس', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802128, N'پي  سيدون', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802129, N'دلياسيرعليا', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802132, N'تمبي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802133, N'تنگ', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802134, N'تنگ سادات', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802136, N'کهناب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802137, N'قلعه  رييس', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802138, N'بناري  شعطي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802140, N'القچين عليا', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802141, N'اوند', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802142, N'المور', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802143, N'نشان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802144, N'گهناب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802146, N'برديان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802147, N'قلم  رييس', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802200, N'بهميي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802201, N'بهميي  گرمسيري  جنوبي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802202, N'ليکک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802203, N'بهميي  گرمسيري  شمالي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802204, N'قلعه  ممبي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802205, N'سراسياب يوسفي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802300, N'چاروسا', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802301, N'طيبي  سرحدي  شرقي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802302, N'جاروده', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802303, N'طيبي  سرحدي  غربي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802304, N'قلعه  رييسي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802400, N'ديشموک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802401, N'بهميي  سرحدي  شرقي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802402, N'اجم', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802403, N'پاتاوه  اجم', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802404, N'بهميي  سرحدي  غربي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802405, N'اسفندان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802500, N'چرام', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802501, N'کره  شهبازي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802502, N'سرفارياب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802503, N'برافتاب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802600, N'لنده', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802601, N'طيبي  گرمسيري  شمالي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802602, N'عالي  طيب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802603, N'چهارراه  عالي  طيب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802604, N'طيبه  گرمسيري', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802901, N'سنقراباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802902, N'طوليان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802903, N'امامزاده  محمود', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802904, N'سريري', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802905, N'کوشک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802906, N'کتج', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802907, N'ابريزک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802908, N'کوه  راک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802909, N'باغ  ملک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802910, N'بناري  سفلي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802911, N'دره  زنگ', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802912, N'دم  طبوح', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802913, N'چهارگود', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802914, N'عروه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802915, N'بهمن ياري', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802916, N'خانک بالا', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802917, N'شيخ  هابيل', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802918, N'سريري  مشدي  اسد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802919, N'قلعه  راک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802920, N'روشن اباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802921, N'ده  شيخ', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802922, N'فيلگاه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802923, N'بيشه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802925, N'دره  کن', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802926, N'پاطاوه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802927, N'پاوه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802928, N'پايين زرد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802929, N'اتشگاه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802930, N'ابمو', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802931, N'اميرآباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802932, N'پوده', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802933, N'خرکده', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802934, N'ده  قاضي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802935, N'پيلي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802936, N'بهارقلم', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802937, N'دلياسير', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802938, N'دره  بيک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802939, N'قلعه  جلو', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802940, N'کهپات', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802941, N'سيلاب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802942, N'تل  بابنه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802943, N'اسکندري', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802944, N'تلخ  اب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802945, N'تل  گرد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802946, N'تلوندي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802947, N'کاظم  اباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802948, N'تنگ ناياب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802950, N'درغک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802951, N'برم  شيراصله', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802952, N'اپقچين سفلي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802953, N'کتا', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802954, N'دم  عباس', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802955, N'تيرابگوسه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802956, N'سيداباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802957, N'سريري  لندي  اسد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802958, N'رودتلخ', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802959, N'سرماهو', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802960, N'جندارقوي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802961, N'دم  تنگ', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802962, N'ادرکان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802963, N'شوتاور', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802964, N'عزيزي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802965, N'کونديده', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802966, N'دم  تنگ عروه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802967, N'القجين سفلي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802968, N'جلو', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802969, N'شيخ  حسين', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802970, N'مونه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802971, N'معيخ  حسين', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802972, N'گرداب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802973, N'مال  ملاسفلي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802974, N'مهد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802975, N'لير', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802976, N'گلاب', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802977, N'گچي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802978, N'ليرکوچک', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802979, N'ناصراباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802980, N'مال  اخوند', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2802981, N'حومه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803000, N'گچساران', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803100, N'مرکزي  گچساران', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803101, N'دوگنبدان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803102, N'ليشتر', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803103, N'علي  ابادليشتر', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803104, N'بويراحمدگرمسيري', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803105, N'ديل', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803106, N'امام  زاده  جعفر', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803107, N'بي  بي  حکيمه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803108, N'باباکلان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803200, N'باشت', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803201, N'بابويي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803202, N'کوه  مره  خامي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803203, N'ابدهگاه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803205, N'باشت وبابويي', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803901, N'چهارتنگ', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803902, N'ارد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803903, N'خريل', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803904, N'اشرين', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803905, N'شابهرام', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803906, N'کگله', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803907, N'شامبراکان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803908, N'خان احمد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803910, N'بابامحمد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803911, N'باباي  کلان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803912, N'اب شيرين', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803914, N'کلگه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803915, N'تل  چگاه', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803916, N'بندعلي  ياري', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803917, N'مارين', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803918, N'لکه  گان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803919, N'منصوراباد', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2803920, N'نازمکان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2899902, N'سردرود', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2899903, N'پشکر', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2899904, N'صيدان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2899905, N'اشيان', N'کهکيلويه  وبويراحمد', 28)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2900000, N'استان زنجان', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901000, N'زنجان', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901100, N'مرکزي  زنجان', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901101, N'بوغداکندي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901102, N'بناب', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901103, N'تهم', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901104, N'همايون', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901105, N'زنجانرودبالا', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901106, N'اسفنجين', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901107, N'قره  پشتلوي  پايين', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901108, N'قبله  بلاغي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901109, N'قره  پشتلوي  بالا', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901110, N'ارمغانخانه', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901111, N'معجزات', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901112, N'اژدهاتو', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901113, N'قلتوق', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901200, N'ايجرود', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901201, N'ايجرودبالا', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901202, N'زرين اباد -  ايجرود', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901203, N'ايجرودپايين', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901204, N'حلب', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901205, N'سعيداباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901300, N'انگوران', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901301, N'دندي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901302, N'قلعه  جوق', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901303, N'سونتو', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901400, N'زنجانرود', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901401, N'زنجانرودپايين', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901402, N'نيک پي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901403, N'چابپاره  بالا', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901404, N'قره  بوته', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901405, N'چابپاره  پايين', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901406, N'حصار', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901407, N'غني  بيگلو', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901408, N'اندابادعليا', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901500, N'طارم  عليا', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901501, N'اب بر', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901502, N'گيلوان', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901503, N'چورزق', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901504, N'درام', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901505, N'دستجرده', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901600, N'ماه  نشان', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901601, N'قزل  گچيلو', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901602, N'قره  گل', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901603, N'اورياد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901604, N'پري', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901901, N'گنج  اباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901902, N'مياندره', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901903, N'محسن اباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901904, N'هليل  اباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901905, N'خو1يين', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901906, N'سياه  رود', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901907, N'ريحان', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901908, N'سنگر', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901909, N'کرزبر', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901910, N'شيخله', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901911, N'قيطول', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2901912, N'سهندسفلي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902000, N'ابهر', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902100, N'مرکزي  ابهر', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902101, N'ابهررود', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902102, N'کينه  ورس', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902103, N'حومه -  مرکزي  ابهر', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902104, N'شريف اباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902105, N'دولت آباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902106, N'درسجين', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902200, N'خرمدره', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902201, N'صايين قلعه', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902202, N'هيدج', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902203, N'قلعه  حسينه', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902204, N'عميداباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902300, N'سلطانيه', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902301, N'قره  بلاغ', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902302, N'سنبل  اباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902303, N'گوزلدره', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902304, N'گوزلدره  سفلي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902901, N'بوجي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902902, N'ارهان', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902903, N'اسلام آباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902904, N'قفس اباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2902905, N'کبودچشم', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903000, N'تاکستان', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903100, N'مرکزي  تاکستان', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903101, N'قاقازان شرقي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903102, N'يحيي  اباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903103, N'قاقازان غربي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903104, N'نيکويه', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903105, N'نرجه', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903200, N'ضيااباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903201, N'دودانگه  عليا', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903202, N'فارسجين', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903203, N'دودانگه  سفلي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903204, N'حسين آباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903300, N'خرمدشت', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903301, N'رامندشمالي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903302, N'نهاوند', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903303, N'افشاريه', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903304, N'رحيم آباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903901, N'اسيان', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2903902, N'کلنجين', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904000, N'خدابنده', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904100, N'مرکزي  خدابنده', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904101, N'قيدار', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904102, N'کرسف', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904103, N'حومه -  مرکزي  خدابنده', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904104, N'دوتپه  سفلي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904105, N'سهرورد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904106, N'خرارود', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904107, N'محمودآباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904200, N'سجاس رود', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904201, N'اقبلاق', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904300, N'افشار', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904301, N'گرماب', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904302, N'شيوانات', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904303, N'قشلاقات افشار', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904304, N'باش قشلاق', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904400, N'بزينه  رود', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904401, N'کهلا', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904402, N'زرينه  رود', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904403, N'زرين اباد -  بزينه  رود', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2904901, N'نوراباد', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2999901, N'سيردان', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2999902, N'دودانگه', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2999903, N'دشت ابي', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2999904, N'چايبار', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (2999905, N'ابر', N'زنجان', 29)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3100000, N'استان خراسان جنوبي', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3101000, N'بيرجند', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3101100, N'مرکزي  بيرجند', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3101200, N'خوسف', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3102000, N'سربيشه', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3102100, N'مرکزي  سربيشه', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3102200, N'مود', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3103000, N'قاينات', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3103100, N'مرکزي  قاينات', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3103101, N'قاين', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3103102, N'اسفدن', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3103200, N'سده', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3103201, N'ارين شهر', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3103300, N'نيمبلوک', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3103302, N'خضري  دشت بياض', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3103400, N'زيرکوه', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3103401, N'حاجي آباد', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3103500, N'زهان', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3104000, N'نهبندان', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3104100, N'مرکزي  نهبندان', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3104200, N'شوسف', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3105000, N'سرايان', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3105100, N'مرکزي  سرايان', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3105102, N'ايسک', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3105200, N'سه  قلعه', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3106000, N'درميان', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3106100, N'مرکزي  درميان', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3106101, N'اسديه', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3107000, N'فردوس', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3107100, N'بشرويه', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (3108000, N'طبس', N'خراسان جنوبي', 31)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4400000, N'استان مرکزي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401000, N'اراک', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401100, N'مرکزي  اراک', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401101, N'سنجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401102, N'مشک اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401104, N'معصوميه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401105, N'سده', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401106, N'مشهدميقان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401107, N'ايپک اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401108, N'ساروق', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401109, N'اميريه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401110, N'مرزيجران', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401111, N'امان اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401112, N'شمس اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401113, N'قاسم  اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401114, N'داوداباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401200, N'خنداب', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401201, N'دهچال', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401202, N'سنگ سفيد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401203, N'طورگير', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401204, N'اناج', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401205, N'جاورسيان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401206, N'سيران', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401207, N'ايجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401208, N'سوزان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401300, N'وفس', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401301, N'کميجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401302, N'اسفندان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401303, N'خنجين', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401304, N'خسروبيک', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401305, N'ميلادجرد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401307, N'درويشان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401308, N'چوگان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401901, N'کرهکرود', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401902, N'طرسزد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401903, N'فريداباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401904, N'عيزجه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401905, N'سنگ کور', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401906, N'ابراهيم آباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401907, N'سمقاور', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401908, N'انجدان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401909, N'ده  نو', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401910, N'فيجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401911, N'چشمه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401912, N'جمال  اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401913, N'موت اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401914, N'نمک کور', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401915, N'گنجگلي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401916, N'نظم  اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401917, N'مست سفلي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401918, N'مست عليا', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401919, N'مزيداباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4401920, N'مشهدالکوبه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4402000, N'اشتيان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4402100, N'مرکزي  اشتيان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4402101, N'مزرعه  نو', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4402102, N'گرگان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4402103, N'سياوشان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403000, N'تفرش', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403100, N'مرکزي  تفرش', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403101, N'رودبار', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403102, N'جغتان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403103, N'بارزجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403104, N'خرازان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403105, N'خانک', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403106, N'کوه  پناه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403107, N'شهراب', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403200, N'فراهان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403201, N'فرمهين', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403202, N'فشک', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403901, N'کهبوعليا', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403902, N'عزيزاباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403903, N'مجدابادکهنه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4403904, N'رودبارتفرش', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404000, N'خمين', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404100, N'مرکزي  خمين', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404101, N'اشناخور', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404102, N'دهنو', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404103, N'حمزه  لو', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404104, N'سرکويه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404105, N'خرم  دشت', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404106, N'قورچي  باشي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404107, N'رستاق', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404108, N'فرنق', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404109, N'صالحان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404110, N'گلدشت', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404111, N'گله  زن', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404112, N'رباطمراد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404113, N'امام  زاده  يوجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404114, N'چهارچشمه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404901, N'قيدو', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404902, N'خشتيجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404903, N'کوکه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404904, N'تلخستان سفلي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404905, N'خوگان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404906, N'دره', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404907, N'طنجران', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404908, N'ورچه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404909, N'ميشيجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4404910, N'لوزدر', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4405000, N'دليجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4405100, N'مرکزي  دليجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4405101, N'نراق', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4405102, N'دودهک', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4405103, N'هستيجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4405104, N'جاسب', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4405105, N'وسقونقان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4405106, N'جوشق', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4405107, N'خرنق', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4405108, N'نصرت اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406000, N'ساوه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406100, N'مرکزي  ساوه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406101, N'شاهسونکندي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406102, N'قيطانيه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406103, N'طرازناهيد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406104, N'قره  چاي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406105, N'نورعلي  بيک', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406106, N'يل  اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406200, N'خرقان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406201, N'الوير', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406202, N'دوزج', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406203, N'عليشار', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406300, N'زرند', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406301, N'مامونيه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406302, N'زاويه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406303, N'رحيم آباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406304, N'حکيم  اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406305, N'خشکرود', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406306, N'رودشور', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406400, N'نوبران', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406401, N'غرق  اباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406402, N'اق  کهريز', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406403, N'پيمان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406404, N'بيات', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406405, N'کوهپايه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406406, N'ياتان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406901, N'قشلاق  مزرعه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406902, N'کره  بر', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406903, N'احمد آباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406905, N'سينک', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406906, N'دانکندي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406907, N'اجان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406908, N'اسيابک', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406909, N'کهک عليا', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406910, N'ديلخي  بلاغ', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406911, N'گوکبلاغ', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406912, N'چمرم', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406913, N'ولامه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406914, N'ويدر', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4406916, N'ميل', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407000, N'سربند', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407100, N'مرکزي  سربند', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407101, N'شازند', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407102, N'استانه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407103, N'عضديه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407104, N'زاليان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407105, N'ده  کاييد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407106, N'قره  کهريز', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407107, N'هفته', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407108, N'پل  دواب', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407109, N'توره', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407110, N'نهرميان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407200, N'هندودر', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407202, N'مالمير', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407203, N'حشيان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407204, N'حاجي  بک', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407901, N'مکه  جوب', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407902, N'مصرلو', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407903, N'خيان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407904, N'دزداندره', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407905, N'ضيااباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407906, N'سالمير', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407907, N'گاوگدار', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407908, N'بازنه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407909, N'کميشان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407910, N'تواندشت سفلي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407911, N'رستمراه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407912, N'قدمگاه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407913, N'تلفتسان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407914, N'تجره', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407915, N'آب بخشان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407916, N'گزطاف عليا', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4407917, N'قره  قيه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4408000, N'محلات', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4408100, N'مرکزي  محلات', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4408101, N'نيمور', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4408102, N'باقرآباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4408103, N'خورهه', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499901, N'راونج', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499902, N'جعفرآباد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499903, N'شرا', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499904, N'کزاز', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499905, N'طغرود', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499906, N'کله  زن', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499907, N'دستجرد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499908, N'دالايي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499909, N'رازقان', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499910, N'آبگرم', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499911, N'فراهان سفلي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499912, N'فراهان عليا', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499913, N'بزچلو', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499914, N'مزدقنچاي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499915, N'مشهداردهال', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499916, N'مشهد', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4499917, N'رزقنجاي', N'مرکزي', 44)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900000, N'استان البرز', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900001, N'ادران', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900002, N'ارنگه', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900003, N'اسارا', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900004, N'افشاريه  کرج', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900005, N'پلنگ اباد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900006, N'خچره', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900007, N'سرخه  حصار', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900008, N'سيجان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900009, N'صالح  اباد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900010, N'عباس اباد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900011, N'نسا', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900012, N'شهرقدس', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900013, N'کاظم  اباد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900016, N'کماکان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900017, N'کمال  اباد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900018, N'کمال  شهر', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900019, N'گرمدره', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900020, N'فرحناز', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900021, N'مرکزي  کرج', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900022, N'مشکين دشت', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900023, N'مهرشهر', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900024, N'نجم  اباد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900026, N'وشته', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4900027, N'ولداباد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901000, N'ساوجبلاغ', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901001, N'چندار', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901002, N'حسن بکول', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901003, N'خواجه  جمال  الدين', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901004, N'سعيداباد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901005, N'عليشاه  عوض', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901007, N'مرکزي  ساوجبلاغ', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901008, N'هشتگرد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901009, N'هيو', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901100, N'طالقان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901101, N'بالاطالقان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901102, N'پايين طالقان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901103, N'شهرک طالقان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901104, N'صفرخواجه', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901105, N'عرب ابادکوه', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901106, N'علي آباد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901107, N'فشند', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901108, N'ميان طالقان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4901109, N'نجم  اباد -  طالقان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4902000, N'نظراباد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4902001, N'بختيار', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4902002, N'اميريان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4902003, N'برغان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4902004, N'تنکمان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4902005, N'جوستان', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4902006, N'رامجين', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4902007, N'شهراسر', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4902008, N'شيخ  حسن', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4902009, N'جمال  الدين', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4903000, N'ماهدشت', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4904000, N'محمدشهر', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4904001, N'محمدآباد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4905000, N'اشتهارد', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4906000, N'فرديس', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (4906001, N'چهار باغ', N'البرز', 49)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5500000, N'استان گيلان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501000, N'رشت', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501100, N'مرکزي  رشت', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501101, N'پسيخان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501102, N'خشت مسجد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501103, N'پيربازار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501104, N'لاکان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501105, N'حومه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501106, N'دارسازي  خناچاه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501200, N'خمام', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501201, N'چاپارخانه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501202, N'کته  سرخمام', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501203, N'کته  سر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501204, N'جوکام', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501205, N'بالامحله', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501300, N'خشک بيجار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501301, N'حاجي  بکنده  خشک بيجار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501302, N'حاجي  بکنده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501303, N'نوشرخشک بيجار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501304, N'نوشر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501400, N'سنگر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501401, N'ويشکاننک', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501402, N'سراوان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501403, N'اسلام آباد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501500, N'کوچصفهان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501501, N'بلسبنه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501502, N'لولمان -  کوچصفهان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501503, N'پيربست لولمان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501504, N'کنارسر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501505, N'کنارسربزرگ', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501506, N'نويده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501600, N'لشت نشا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501601, N'کفشه  لشت نشا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501602, N'بالاکفشه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501603, N'جيرهنده  لشت نشا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501604, N'جيرهنده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501605, N'علي  ابادزيباکنار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501606, N'زيباکنار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501608, N'توچاه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501609, N'چاقوچاه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501901, N'ماشک', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501902, N'لچه  گوراب', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501903, N'سروندان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501904, N'شيجان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501905, N'پشکه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501906, N'پيرموسي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501907, N'کدوسرا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501908, N'جعفرآباد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501909, N'بيجارکنار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501910, N'رودکل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5501911, N'کيلوه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5502000, N'استارا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5502100, N'مرکزي  استارا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5502101, N'حيران', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5502102, N'کيلاده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5502103, N'لوندويل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5502104, N'ويرموني', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5502902, N'دگرمانکشي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5502903, N'تله  خان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503000, N'استانه  اشرفيه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503100, N'مرکزي  استانه  اشرفيه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503200, N'کياشهر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503901, N'لشکام', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503902, N'پنچاه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503903, N'داخل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503905, N'لسکوکلايه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503907, N'گورکا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503908, N'کشل  ازادسرا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503909, N'کيسم', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503910, N'دهشال', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503911, N'چهارده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503912, N'شيرکوه  چهارده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503914, N'دهسر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5503915, N'دهگاه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5504000, N'بندرانزلي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5504100, N'مرکزي  بندرانزلي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5504101, N'چهارفريضه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5504102, N'کپورچال', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5504103, N'ابکنار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5504104, N'خميران', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5504107, N'ليچارگي  حسن رود', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505000, N'رودبار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505100, N'مرکزي  رودبار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505101, N'رستم  اباد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505102, N'منجيل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505103, N'لوشان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505104, N'رستم  ابادجنوبي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505105, N'رستم  ابادشمالي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505106, N'اسکولک', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505108, N'کلشتر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505200, N'رحمت ابادوبلوکات', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505201, N'توتکابن', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505202, N'رحمت اباد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505203, N'بلوکات', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505204, N'شهربيجار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505205, N'دشتويل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505208, N'جمال  اباد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505300, N'عمارلو', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505301, N'جيرنده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505302, N'کليشم', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505303, N'خورگام', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505304, N'بره  سر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505305, N'دلفک', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505306, N'چهارمحل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505901, N'لاکه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505902, N'گردويشه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5505903, N'ماست خور', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506000, N'رودسر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506100, N'مرکزي  رودسر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506101, N'کلاچاي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506102, N'چابکسر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506103, N'واجارگاه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506104, N'چيني  جان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506105, N'رضامحله', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506106, N'اوشيان وسياهکل  رود', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506107, N'چاي  جان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506108, N'ماچيان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506200, N'املش', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506201, N'املش شمالي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506202, N'کهنه  گوراب', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506203, N'شبخوس لات', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506204, N'سمام', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506205, N'ملکوت', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506206, N'کجيد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506207, N'املش جنوبي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506208, N'حاجي آباد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506300, N'رحيم آباد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506301, N'طول  لات', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506302, N'شوييل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506303, N'اشکورعلياوسيارستاق', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506304, N'سارم', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506305, N'اشکورسفلي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506306, N'زيار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506307, N'تازه  اباد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506901, N'شيخ  زاهدمحله', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506902, N'امام', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5506903, N'بي  بالان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507000, N'صومعه  سرا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507100, N'مرکزي  صومعه  سرا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507101, N'طاهرگوراب', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507102, N'ضيابر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507103, N'کسما', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507104, N'تولم  شهر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507200, N'ميرزاکوچک جنگلي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507201, N'گوراب زرميخ', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507202, N'مرکيه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507300, N'تولم', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507301, N'مرجقل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507302, N'ليف شاگرد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507303, N'هندوخاله', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507901, N'دليوندان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507902, N'اباتر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507903, N'چشمه  سر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507904, N'چمشقال', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507905, N'دوگور', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5507906, N'اشپلم', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508000, N'طوالش', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508100, N'مرکزي  طوالش', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508101, N'هشتپر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508102, N'ساحلي  جوکندان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508103, N'چلونصر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508104, N'کوهستاني  طالش', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508105, N'کيش ديبي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508106, N'اسالم', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508107, N'طولارود', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508200, N'گرگان رود', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508201, N'حويق', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508202, N'ليسار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508300, N'رضوانشهر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508301, N'پره  سر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508302, N'گيل  دولاب', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508303, N'دارسرا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508304, N'ديناچال', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508305, N'بازارديناچال', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508306, N'خوشابر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508307, N'شنگاور', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508308, N'ييلاقي  ارده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508309, N'ارده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508400, N'ماسال  شاندرمن', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508401, N'ماسال', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508402, N'تاسکوه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508403, N'شاندرمن', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5508404, N'بازارجمعه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509000, N'فومن', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509100, N'مرکزي  فومن', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509101, N'ماسوله', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509102, N'گشت', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509103, N'اليان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509104, N'سياهرود', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509105, N'گوراب پس', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509106, N'لولمان -  مرکزي  فومن', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509107, N'رودپيش', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509108, N'سردارجنگل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509109, N'بالاماکلوان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509901, N'حسين آباد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509902, N'چيران', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509903, N'للکام', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509904, N'لکده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5509905, N'پيرده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5510000, N'شفت', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5510100, N'مرکزي  شفت', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5510101, N'جيرده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5510102, N'ملاسرا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5510200, N'احمدسرگوراب', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5510201, N'چوبر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5510202, N'نصيرمحله', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511000, N'لاهيجان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511100, N'مرکزي  لاهيجان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511101, N'اهندان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511102, N'بازکياکوراب', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511103, N'لفمجان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511104, N'بازارلفمجان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511105, N'ليالستان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511106, N'رودبنه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511107, N'شيرجوپشت', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511108, N'بالامحله  ناصرکياده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511109, N'ليل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511110, N'سطل  سر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511200, N'سياهکل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511201, N'توتکي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511202, N'خرارود', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511203, N'مالفجان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511204, N'موشاد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511205, N'بينوند', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511300, N'ديلمان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511301, N'پيرکوه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511302, N'پيرکوه  عليا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5511901, N'بالارودپشت', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512000, N'لنگرود', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512100, N'مرکزي  لنگرود', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512101, N'کومله -  مرکزي  لنگرود', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512102, N'شلمان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512103, N'چاف', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512104, N'چاف پايين', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512105, N'درياسر', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512106, N'ديوشل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512107, N'گل  سفيد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512200, N'اطاقور', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512201, N'کومله -  اطاقور', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512202, N'لات ليل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512902, N'حاجي  سرا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5512903, N'چم  خاله', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599901, N'حسن کياده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599902, N'سيارستاق  ييلاقي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599903, N'بازار', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599904, N'سنديان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599905, N'خطبه  سرا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599906, N'خال  سرا', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599907, N'کلاچلي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599908, N'جوکندان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599909, N'گسگرات', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599910, N'ريک', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599911, N'هره  دشت', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599912, N'استانه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599913, N'پونل', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599914, N'طالشدولاب', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599915, N'بازارماسال', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599916, N'رضوان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599917, N'تولمات', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599918, N'گرگانرودشمالي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599919, N'جماکوه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599920, N'سيارستاق  قشلاقي', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599921, N'سياهکل  رود', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599922, N'شکردشت', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599923, N'فاراب', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599924, N'تالش', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599925, N'ميانده', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599926, N'محمودآباد', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599927, N'ميانکوه', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599928, N'مريان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (5599929, N'ناوان', N'گيلان', 55)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6100000, N'استان اردبيل', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101000, N'اردبيل', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101100, N'مرکزي  اردبيل', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101101, N'سرعين', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101102, N'ارشق  شرقي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101103, N'تقي  ديزج', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101104, N'بالغلو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101105, N'شام  اسبي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101106, N'سبلان', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101107, N'ارديموسي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101108, N'سردابه', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101109, N'خشکه  رود', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101110, N'کلخوران', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101111, N'کلخوران شيخ', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101112, N'آبگرم', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101113, N'ورنياب', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101114, N'شرقي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101115, N'نيار', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101116, N'غربي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101117, N'ثمرين', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101200, N'نمين', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101201, N'دولت آباد', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101202, N'گرده', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101204, N'عنبران سفلي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101205, N'ويلکيج  جنوبي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101206, N'حور', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101207, N'ويلکيج  شمالي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101208, N'ننه  کران', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101209, N'ويلکيج  مرکزي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101210, N'ابي  بيگلو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101300, N'نير', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101301, N'دورسونخواجه', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101302, N'اسلام آباد -  نير', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101303, N'رضاقلي  قشلاق', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101304, N'يورتچي  شرقي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101305, N'کوراييم', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101306, N'يورتچي  غربي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101307, N'قره  شيران', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101308, N'مهماندوست', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101309, N'مهماندوست عليا', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101400, N'هير', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101401, N'فولادلوي  جنوبي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101402, N'بودالالو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101403, N'فولادلوي  شمالي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101404, N'ازادلوي  بزرگ', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101901, N'گللو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101902, N'ازچه', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101903, N'عنبران', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101904, N'خانقاه  عليا', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101905, N'خوام', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101906, N'خرام', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101907, N'رضي  اباد', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101908, N'باروق', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101909, N'جله  کران', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101910, N'کورعباسلو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101911, N'پيله  رود', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101912, N'اقاباقر', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101913, N'خوش اباد', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6101914, N'قره  تپه', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6102000, N'بيله  سوار', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6102100, N'مرکزي  بيله  سوار', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6102101, N'انجيرلو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6102102, N'گوگ تپه', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6102200, N'قشلاق  دشت', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6102201, N'جعفرآباد', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6102202, N'قشلاق  جنوبي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6102203, N'شورگل', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6102204, N'قشلاق  شرقي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103000, N'پارس اباد', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103100, N'مرکزي  پارس اباد', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103101, N'تازه  کند', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103102, N'تازه  کندقديم', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103103, N'ساوالان', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103104, N'گوشلو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103105, N'قشلاق  شمالي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103106, N'اسلام آباد -  مرکزي  پارس اباد', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103200, N'اصلاندوز', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103201, N'قشلاق  غربي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103202, N'بوران عليا', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6103901, N'باقرلو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104000, N'خلخال', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104100, N'مرکزي  خلخال', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104101, N'خانندبيل  شرقي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104102, N'خوجين', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104103, N'خانندبيل  غربي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104104, N'گزاز', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104105, N'سنجبدشرقي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104106, N'لنبر', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104200, N'خورش رستم', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104201, N'هشتجين', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104202, N'خورش رستم  جنوبي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104203, N'برندق', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104204, N'خورش رستم  شمالي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104300, N'سنجبد', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104301, N'گيوي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104302, N'سنجبدجنوبي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104303, N'فيروزاباد', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104304, N'سنجبدشمالي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104305, N'خلف لو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104306, N'سنجبدغربي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104307, N'گنجگاه', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104400, N'شاهرود', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104401, N'کلور', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104402, N'پلنگا', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104403, N'کرين', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104404, N'شال', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104901, N'مجره', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104902, N'کيوي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104904, N'مرشت', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104905, N'گيلوان', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104906, N'منجبد', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104907, N'هشجين', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6104908, N'ميل  اغاردان', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105000, N'گرمي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105100, N'مرکزي  گرمي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105101, N'اجارودشرقي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105102, N'زهرا', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105103, N'اجارودغربي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105104, N'ديزج', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105105, N'اجارودمرکزي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105106, N'حمزه  خانلو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105107, N'اجارودشمالي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105108, N'شکراب', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105109, N'اني', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105200, N'انگوت', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105201, N'انگوت شرقي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105202, N'تازه  کندانگوت', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105203, N'انگوت غربي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105204, N'قره  اغاج  پايين', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6105205, N'پايين برزند', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106000, N'مشگين شهر', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106100, N'مرکزي  مشگين شهر', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106101, N'دشت', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106102, N'عباس ابادپري  خان', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106103, N'شعبان', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106105, N'الي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106106, N'مشگين غربي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106107, N'قصابه', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106200, N'مشگين شرقي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106201, N'قره  سو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106203, N'فخراباد', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106204, N'نقدي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106205, N'نقدي  عليا', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106206, N'لاهرود', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106300, N'ارشق', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106301, N'ارشق  شمالي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106302, N'قوشه  سفلي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106303, N'ارشق  غربي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106304, N'مرادلو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106305, N'ارشق  مرکزي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106306, N'رضي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106307, N'صلوات', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106308, N'يافت', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106309, N'گنجويه', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106500, N'کوثر', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106901, N'قاسم  کندي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106902, N'کوحبق', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6106903, N'محمدي', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6199901, N'اقبلاغ', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6199902, N'ميرزارحيم  لو', N'اردبيل', 61)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6200000, N'استان قم', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201000, N'قم', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201100, N'مرکزي  قم', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201101, N'راهجردشرقي', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201102, N'سلفچگان', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201103, N'قمرود', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201104, N'قنوات', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201105, N'حاجي  ابادلکها', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201106, N'قورکچل', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201200, N'جعفرآباد', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201201, N'گازران', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201300, N'خلجستان', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201301, N'دستجرد', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201302, N'قاهان', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201400, N'نوفل  شاتو', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201401, N'فردو', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201402, N'ميم', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201403, N'کهک', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201404, N'نيزار', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6201916, N'اسلام آباد', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299901, N'ديزج', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299902, N'حسن آباد', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299904, N'دتنوه', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299905, N'راهجردغربي', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299906, N'بيوهمند', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299907, N'ديزار', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299908, N'حرم', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299909, N'باغک', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299910, N'راهجرد', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299911, N'محمدآباد', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299912, N'ونان', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299913, N'وشنوه', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6299914, N'نوراباد', N'قم', 62)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6300000, N'استان قزوين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301000, N'قزوين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301001, N'راجرجين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301002, N'رحمت اباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301003, N'رحيم آباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301004, N'رودبارالموت', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301005, N'رودبارقزوين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301006, N'ريال  اباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301007, N'زاچکان عليا', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301008, N'سياه  دشت', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301009, N'علي آباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301010, N'فلار', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301011, N'قاقازان', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301012, N'قرانچال', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301013, N'قليچ  کندي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301014, N'کله  دره', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301015, N'کورطل', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301016, N'کوه  گيرسفلي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301017, N'محمودآباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301018, N'مرکزي  قزوين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301019, N'مزرعه  بشر', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301020, N'مشکين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301021, N'ميان پالان', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301022, N'نارنده', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301023, N'نظام  اباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301024, N'وندر', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301025, N'يروان', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301026, N'يوزباشي  چايي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301027, N'حصارخزران', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301028, N'خرمن سوخته', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301102, N'اقبال  شرقي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301103, N'اقبال  غربي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301104, N'پيريوسفان', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301105, N'ايلات قاقازان شرقي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301106, N'ايلات قاقازان غربي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301107, N'شريف اباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301108, N'کورانه', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301109, N'محمودابادنمونه', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301110, N'اق  بابا', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301111, N'کوهين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301200, N'رودبارشهرستان', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301202, N'رودبارمحمدزماني', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301203, N'دستجرد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301204, N'بهرام  اباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301205, N'رجايي  دشت', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301206, N'دستجردسفلي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301300, N'الموت', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301301, N'الموت بالا', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301302, N'الموت پايين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301303, N'معلم  کلايه', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301304, N'مينودشت', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301305, N'زوارک', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301400, N'طارم  سفلي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301401, N'چوقور', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301402, N'خندان', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301403, N'نيارک', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301404, N'کوهگير', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301405, N'حصار', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301406, N'سياهپوش', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301500, N'ابيک', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301501, N'بشاريات', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301502, N'کوهپايه  شرقي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301503, N'کوهپايه  غربي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301504, N'زياران', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301505, N'خاکعلي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301506, N'ناصراباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301507, N'کوندج', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6301600, N'البرز', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302000, N'بويين زهرا', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302100, N'مرکزي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302101, N'بويين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302102, N'زهراي  بالا', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302103, N'زهراي  پايين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302104, N'دشتابي  شرقي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302105, N'دشتابي  غربي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302106, N'سگزاباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302107, N'عصمت اباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302109, N'شهرستانک', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302110, N'ارداق', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302200, N'اوج', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302201, N'آبگرم', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302202, N'حصاروليعصر', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302203, N'خرقان شرقي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302204, N'خرقان غربي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302205, N'شهيداباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302206, N'کلنجين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302207, N'نيارج', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302300, N'رامند', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302301, N'دانسفهان', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302302, N'ابراهيم آباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302303, N'رامندجنوبي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302304, N'خوزنين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302400, N'شال', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302401, N'زين اباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302402, N'قلعه  هاشم', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6302403, N'شهرک مدرس', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303000, N'تاکستان', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303100, N'اسفرورين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303101, N'اک', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303102, N'خرم آباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303202, N'قاقازان شرقي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303203, N'قاقازان غربي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303204, N'نرجه', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303205, N'يحيي  اباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303206, N'نيکويه', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303300, N'ضيااباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303301, N'دودانگه  عليا', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303302, N'دودانگه  سفلي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303303, N'فارسجين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303304, N'حسين آباد', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303400, N'خرمدشت', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303401, N'رامندشمالي', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303402, N'افشاريه', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303403, N'نهاوند', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303405, N'الوند', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303406, N'محمديه', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303407, N'اقابابا', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303408, N'اقباليه', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6303409, N'بادمجين', N'قزوين', 63)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6400000, N'استان گلستان', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401000, N'گرگان', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401100, N'مرکزي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401102, N'استرابادجنوبي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401103, N'استرابادشمالي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401104, N'انجيراب', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401105, N'روشن اباد', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401106, N'سرخ  پشته', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401107, N'جلين عليا', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401108, N'سرخنکلاته', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401109, N'رنگيان', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401110, N'لمسک', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401111, N'نوده  ملک', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401200, N'اق  قلا', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401202, N'اق  التين', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401203, N'شيخ  موسي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401204, N'گرگان بوي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401206, N'عطااباد', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401207, N'گري  دوجي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401208, N'قنقرمه', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6401209, N'انبارالوم', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6402000, N'ترکمن', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6402101, N'بندرترکمن', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6402102, N'جعفرياي  جنوبي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6402103, N'سيجوال', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6402200, N'گميشان', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6402201, N'گميش تپه', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6402202, N'جعفرياي  شرقي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6402203, N'جعفرياي  غربي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6402204, N'بناور', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6402205, N'خواجه  نفس', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6403000, N'کردکوي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6403102, N'چهارکوه', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6403103, N'سدن رستاق  شرقي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6403104, N'سدن رستاق  غربي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6403105, N'سرکلاته', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6403106, N'يساقي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6403107, N'چهارده', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6404000, N'علي آباد', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6404102, N'استراباد', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6404103, N'کتول', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6404104, N'فاضل  اباد', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6404105, N'مزرعه', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405000, N'گنبدکاووس', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405102, N'اق  اباد', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405103, N'باغلي  مارما', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405104, N'فجر', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405105, N'سلطانعلي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405200, N'ازادشهر', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405202, N'چشمه  ساران', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405203, N'خرمارود', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405204, N'نظام  اباد', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405205, N'فارسيان -  ازادشهر', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405206, N'نوده  خاندوز', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405300, N'داشلي  برون', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405302, N'اترک', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405303, N'کرند', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405400, N'راميان', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405401, N'خان ببين', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405402, N'دلند', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405403, N'فندرسک', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405404, N'قلعه  ميران', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405405, N'دارکلاته', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6405406, N'باقرآباد', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406000, N'مينودشت', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406102, N'چهل  چاي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406103, N'قلعه  قافه', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406104, N'کوهسارات', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406105, N'الفجر', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406107, N'دوزين', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406200, N'کلاله', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406201, N'اق  سو', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406202, N'تمران', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406203, N'زاوکوه', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406204, N'کنگور', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406205, N'اجن سنگرلي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406206, N'تمرقره  قوزي  سفلي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406207, N'پيشکمر', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406300, N'گاليکش', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406301, N'قراولان', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406302, N'نيلکوه', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406303, N'ينقاق', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406304, N'اق  قميش', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406305, N'فارسيان -  گاليکش', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406400, N'مراوه  تپه', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6406402, N'گلي  داغ', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6407000, N'بندرگز', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6407102, N'انزان غربي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6407103, N'انزان شرقي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6407104, N'گزغربي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6407105, N'گلفرا', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6407200, N'نوکنده', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6407202, N'بنفشه  تپه', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6407203, N'ليوان', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6407204, N'ليوان شرقي', N'گلستان', 64)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6600000, N'استان سيستان وبلوچستان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601000, N'زاهدان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601100, N'مرکزي  زاهدان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601101, N'چشمه  زيارت', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601102, N'حرمک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601200, N'ميرجاوه', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601201, N'لاديز', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601202, N'تمين', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601300, N'نصرت اباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601301, N'حصاروييه', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601302, N'کورين', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601303, N'سرجنگل', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601901, N'لادز', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601902, N'دهک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6601903, N'سعيداباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602000, N'ايرانشهر', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602100, N'مرکزي  ايرانشهر', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602101, N'حومه -  مرکزي  ايرانشهر', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602102, N'شهردراز', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602103, N'ابتر', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602104, N'دامن', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602105, N'زهلنفان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602200, N'بزمان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602201, N'گيمان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602202, N'اب رييس', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602203, N'مسجدابوالفضل', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602300, N'بمپور', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602301, N'بمپورشرقي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602302, N'نوکچوب', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602303, N'بمپورغربي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602304, N'قاسم  اباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602400, N'دلگان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602401, N'گلمورتي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602402, N'هوديان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602403, N'جلگه  چاه  هاشم', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602404, N'چگرد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602500, N'راسک وفيروزاباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602501, N'راسک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602502, N'پيشين', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602503, N'پارود', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602504, N'مورتان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602600, N'سرباز', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602602, N'ايرافشان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602603, N'کجدر', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602604, N'سرکور', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602605, N'مچکوز', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602606, N'کيشکور', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602607, N'رييس اباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602608, N'مينان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602609, N'باتک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6602610, N'نسکند', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603000, N'چابهار', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603001, N'منطقه  ازادچابهار', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603100, N'مرکزي  چابهار', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603101, N'کمبل  سليمان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603102, N'پيرسهراب', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603200, N'کنارک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603201, N'زراباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603202, N'لاش', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603203, N'کهير', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603204, N'جهليان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603300, N'دشتياري', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603301, N'نگور', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603302, N'نوبنديان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603303, N'باهوکلات', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603304, N'سندميرثوبان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6603305, N'پلان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604000, N'خاش', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604100, N'مرکزي  خاش', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604101, N'سنگان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604102, N'پشتکوه', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604103, N'افضل  اباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604104, N'کوه  سفيد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604105, N'بيات اباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604106, N'کارواندر', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604107, N'ايرندگان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604108, N'ده  قلعه', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604109, N'اسماعيل آباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604110, N'عباس اباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604200, N'نوک اباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604201, N'اسکل  اباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604202, N'دهپابيد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604203, N'تفتان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604204, N'تمندان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604205, N'گوهرکوه', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604206, N'گوهرشهر', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6604207, N'نازيل', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605000, N'زابل', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605100, N'مرکزي  زابل', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605101, N'بنجار', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605200, N'پشت اب', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605201, N'بزي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605202, N'بزي  عليا', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605203, N'اديمي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605204, N'قايم  اباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605205, N'سفيدابه', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605300, N'شيب اب', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605301, N'کوه  خواجه', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605302, N'صيادان سفلي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605303, N'تيموراباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605304, N'لوتک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605305, N'محمدآباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605400, N'ميان کنگي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605401, N'قرقري', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605402, N'مارگان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605403, N'دوست محمد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605404, N'جهان اباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605405, N'جهان ابادسفلي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605500, N'شهرکي  ونارويي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605501, N'زهک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605502, N'خمک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605503, N'جزينک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605504, N'خواجه  احمد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605902, N'دهباشي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6605903, N'گزم  ابراهيم  اباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606000, N'سراوان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606100, N'مرکزي  سراوان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606101, N'حومه -  مرکزي  سراوان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606102, N'ده  محمدي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606103, N'گشت', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606200, N'بم  پشت', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606201, N'سيرکان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606202, N'کوهک اسفندک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606203, N'اسفندک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606204, N'کشتگان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606300, N'جالق', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606301, N'ناهوک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606302, N'کشکوک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606303, N'کله  گان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606400, N'زابلي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606401, N'بيرک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606402, N'چاهوک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606500, N'سيب وسوران', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606501, N'سوران', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606502, N'پسکوه', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6606503, N'هيدوج', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607000, N'نيک شهر', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607100, N'مرکزي  نيک شهر', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607101, N'مخت', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607102, N'هيچان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607103, N'چاهان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607104, N'مهبان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607200, N'بنت', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607201, N'دستگرد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607202, N'توتان ومهمدان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607203, N'توتان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607300, N'فنوج', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607301, N'مسکوتان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607302, N'گتيج', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607400, N'قصرقند', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607401, N'هلونچگان', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607402, N'ساربوک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607403, N'تلنگ', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607404, N'دنسر', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607500, N'لاشار', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607501, N'لاشارشمالي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607502, N'اسپکه', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607503, N'لاشارجنوبي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607504, N'پيپ', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6607505, N'چانف', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699901, N'شهرکي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699902, N'کلنگور', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699903, N'گوشه', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699904, N'اشار', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699905, N'ده  بالا', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699906, N'ثمين', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699907, N'کنت', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699908, N'فيروزاباد', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699909, N'تخته  شاب', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699910, N'گاسک', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699911, N'شيب اب وپشت اب', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699912, N'پشين', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699913, N'فتوج', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699914, N'شورو', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699915, N'ضيايي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699916, N'انده', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699917, N'چاه  گاوي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699918, N'ملوران', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699919, N'نارويي', N'سيستان وبلوچستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (6699920, N'سيستان وبلوچستان', N'مهرستان', 66)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7700000, N'استان يزد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701000, N'يزد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701100, N'مرکزي  يزد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701101, N'شاهديه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701102, N'حميديا', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701103, N'فجر', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701104, N'خيراباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701105, N'فهرج', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701106, N'محمدآباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701200, N'اشگذر', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701201, N'زارچ', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701202, N'رستاق', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701203, N'بندراباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701204, N'اله  اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701205, N'حسين آباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701206, N'صدراباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701300, N'خضراباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701301, N'کذاب', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701302, N'ندوشن', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701901, N'مهدي  اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701902, N'يعقوبي', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701903, N'نعيم  اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701905, N'محمودآباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701906, N'سرددراپ', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701907, N'تيقوني', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701908, N'کوچه  بيوک', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701909, N'قاسم  اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7701910, N'چنار', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702000, N'اردکان', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702100, N'مرکزي  اردکان', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702101, N'عقدا', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702102, N'محمديه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702103, N'احمد آباد -  مرکزي  اردکان', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702104, N'نارستان', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702105, N'مزرعه  نوحسن اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702200, N'خرانق', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702201, N'رباطات', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702202, N'رباطپشت بادام', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702203, N'زرين', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702204, N'توت', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702901, N'شهيديه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7702902, N'چاه  متک', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703000, N'بافق', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703100, N'مرکزي  بافق', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703101, N'سبزدشت', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703102, N'بساب', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703103, N'مبارکه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703104, N'کوشک', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703200, N'بهاباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703201, N'اسفيچ', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703202, N'بنستان', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703203, N'جلگه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703204, N'احمد آباد -  بهاباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703205, N'ده  عسکر', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703206, N'فشه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703207, N'سنجرک', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7703901, N'خوسف', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704000, N'تفت', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704100, N'مرکزي  تفت', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704101, N'پيشکوه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704102, N'اسلاميه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704103, N'شيرکوه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704104, N'طرزجان', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704105, N'علي آباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704106, N'نصراباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704107, N'دهشير', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704200, N'نير', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704201, N'گاريزات', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704202, N'بخ', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704203, N'بنادکوک', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704204, N'بنادکوک ديزه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704205, N'سخويد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704206, N'توده', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704207, N'زردين', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704208, N'کهدوييه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704209, N'سنگلراز', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704210, N'مريم  اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704211, N'بغداداباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704901, N'سانيج', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704902, N'سعيداباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704903, N'صادق  اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704904, N'نوراباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7704905, N'هدش', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7705000, N'ابرکوه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7705100, N'مرکزي  ابرکوه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7705101, N'فراغه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7705102, N'تيرجرد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7705103, N'شهرسب', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7705200, N'بهمن', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7705201, N'مهراباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7705202, N'اسفندار', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7705901, N'اسفندآباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7705902, N'هروک', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706000, N'مهريز', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706100, N'مرکزي  مهريز', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706101, N'تنگ چنار', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706102, N'خورميز', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706103, N'ميرک اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706104, N'ميانکوه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706105, N'بنادک سادات', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706106, N'ارنان', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706107, N'بهادران', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706200, N'هرات ومروست', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706203, N'فتح  اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706204, N'هرابرجان', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706901, N'بهمن اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706902, N'سريزد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7706903, N'نرويراباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707000, N'ميبد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707100, N'مرکزي  ميبد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707101, N'بفروييه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707901, N'فيروزاباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707902, N'دره  اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707903, N'ده  اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707904, N'بارجين', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707905, N'رکن اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707906, N'حسن آباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707907, N'بيده', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707908, N'خانقاه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7707909, N'اميرآباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7708000, N'صدوق', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7709000, N'طبس', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7709100, N'مرکزي  طبس', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7710000, N'خاتم', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7710100, N'مرکزي  خاتم', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7710200, N'هرات', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7710300, N'مروست', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7799901, N'فيض اباد', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7799902, N'چهارباغ', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7799904, N'قمشه', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7799905, N'مهريادين', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (7799906, N'کاريز', N'يزد', 77)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8800000, N'استان بوشهر', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8801000, N'بوشهر', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8801100, N'مرکزي  بوشهر', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8801101, N'انگالي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8801102, N'کره  بند', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8801103, N'حومه -  مرکزي  بوشهر', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8801104, N'چغادک', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8801200, N'خارک', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8801901, N'بهمني', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802000, N'تنگستان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802100, N'مرکزي  تنگستان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802101, N'اهرم', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802102, N'بازويي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802103, N'باغک', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802104, N'شورکي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802200, N'ساحلي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802201, N'دلوار', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802202, N'بوالخير', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802901, N'سمل', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802902, N'جايينک', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802903, N'قصاب بوالخير', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802904, N'گرگور', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802905, N'اشير', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8802906, N'انبارک', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8803000, N'دير', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8803100, N'مرکزي  دير', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8803101, N'بندردير', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8803102, N'ابدان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8803103, N'حومه -  مرکزي  دير', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8803104, N'دوراهک', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8803200, N'بردخون', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8803201, N'ابکش', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804000, N'دشتستان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804100, N'مرکزي  دشتستان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804101, N'برازجان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804102, N'ارم', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804103, N'تنگ ارم', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804104, N'پشتکوه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804105, N'کلمه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804106, N'دالکي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804107, N'حومه -  مرکزي  دشتستان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804108, N'سرکره', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804109, N'زيارت -  مرکزي  دشتستان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804200, N'سعداباد', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804201, N'زيرراه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804202, N'نظراقا', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804203, N'وحدتيه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804300, N'شبانکاره', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804301, N'درواهي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804901, N'دره  وان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804902, N'سميعي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8804903, N'ابوالفيروز', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805000, N'دشتي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805100, N'مرکزي  دشتي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805101, N'خورموج', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805102, N'بوحيري', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805103, N'درازي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805104, N'شنبه  وطسوج', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805105, N'شنبه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805200, N'کاکي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805201, N'چغاپور', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805202, N'بادوله', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805203, N'کبگان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805204, N'زيارت -  کاکي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805901, N'دشت زال', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8805902, N'محمدآباد', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8806000, N'کنگان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8806100, N'مرکزي  کنگان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8806101, N'بندرکنگان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8806102, N'طاهري', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8806103, N'عسلويه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8806104, N'ناي  بند', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8806105, N'چاه  مبارک', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8806200, N'جم', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8806201, N'ولايت', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8806202, N'ريز', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8806901, N'علي آباد', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8807000, N'گناوه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8807100, N'مرکزي  گناوه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8807101, N'بندرگناوه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8807102, N'حيات داود', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8807103, N'محمدصالحي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8807200, N'ريگ', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8807201, N'بندرريگ', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8807202, N'رودحله', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8807203, N'چهارروستايي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8807901, N'مال  قايه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808000, N'ديلم', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808100, N'مرکزي  ديلم', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808101, N'بندرديلم', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808102, N'ليراوي  شمالي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808103, N'سياه  کان بزرگ', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808104, N'حومه -  مرکزي  ديلم', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808105, N'عامري', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808200, N'بهرگان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808201, N'ليرواي  جنوبي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808202, N'امام  حسن', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808203, N'ليرواي  مياني', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808204, N'والفجر', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808901, N'مال  شهاب', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8808902, N'چاهخاني', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899901, N'خايز', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899902, N'طسوج', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899903, N'کيسکان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899904, N'بندرعسلويه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899905, N'بوشکان', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899906, N'ده  کهنه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899907, N'چاه  کوتاه', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899908, N'مالکي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899909, N'خارلو', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899910, N'مزارعي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899911, N'ثلاث', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899912, N'فارسي', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899913, N'بندرطاهري', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (8899914, N'بندربوشهر', N'بوشهر', 88)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9800000, N'کشورها', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801002, N'انگلستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801003, N'روماني', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801004, N'برزيل', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801005, N'المان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801006, N'هلند', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801007, N'فيليپين', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801008, N'استراليا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801009, N'ژاپن', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801010, N'اردن', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801011, N'فرانسه', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801012, N'پاکستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801013, N'اتريش', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801014, N'امارات متحده', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801015, N'ايتاليا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801016, N'مالزي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801017, N'مصـر', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801018, N'ارمنستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801019, N'بلژيک', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801020, N'فنلاند', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801021, N'آرژانتين', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801022, N'کانادا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801023, N'تایلند', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801100, N'سويد', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801101, N'ازبکستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801102, N'روسيه', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801103, N'يونان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801104, N'لبنان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9801105, N'دبي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802002, N'قطر', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802003, N'کره جنوبی', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802004, N'عراق', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802005, N'کره شمالی', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802006, N'قرقيزستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802007, N'کويت', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802008, N'ترکيه', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802009, N'چین', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802010, N'سوئيس', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802011, N'دانمارک', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802012, N'يوگوسلاوي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802013, N'اذربايجان شوروي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802014, N'قزاقستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802015, N'ترکمنستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802016, N'اسپانيا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802017, N'گرجستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802019, N'تايوان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802021, N'تاجيکستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802022, N'داغستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802100, N'افغانستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802200, N'هندوستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802351, N'بحرين', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802352, N'عمان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802402, N'عربستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802521, N'سوريه', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802522, N'اکراين', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802523, N'لهستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802524, N'سريلانکا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802525, N'ونزوئلا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802526, N'نيوزيلند', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802527, N'بنگلادش', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802528, N'نيجريه', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802529, N'مجارستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9802600, N'هند', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9803000, N'افريقا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9804000, N'امريکاي  شمالي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9804001, N'امريکا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9805000, N'امريکاي  جنوبي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806000, N'اقيانوسيه', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806001, N'بلغارستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806002, N'اندونزی', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806003, N'ويتنام', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806004, N'آلباني', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806005, N'پرتغال', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806006, N'جمهوري چک', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806007, N'بلاروس', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806008, N'سنگاپور', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806009, N'يمن', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806010, N'گواتمالا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806011, N'اکوادور', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806012, N'نروژ', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806013, N'لوکزامبورگ', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806014, N'قبرس', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806015, N'آبهای بین المللی', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806016, N'اسلواکی', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806017, N'ایسلند', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806018, N'تونس', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806019, N'سودان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806020, N'ليتواني', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806021, N'ترينيداد و توباگو', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806022, N'مالتا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806023, N'اسلووني', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806024, N'اتيوپي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806025, N'ایرلند', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806026, N'تانزانيا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806027, N'جيبوتي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806028, N'کنيا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806029, N'مقدونيه', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806030, N'ميانمار', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806031, N'شيلي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806032, N'کامرون', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806033, N'موزامبيک', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806034, N'مغولستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806035, N'الجزاير', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806036, N'پاراگوئه', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806037, N'اسکاتلند', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806038, N'صربستان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806039, N'استوني', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806040, N'بوسني هرزگوين', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806041, N'کرواسي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806042, N'غنا', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806043, N'جمهوري سيشل', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806044, N'سنگال', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806045, N'ساحل عاج', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806046, N'جمهوري توگو', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806047, N'نيجر', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806048, N'آفريقاي جنوبي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806049, N'جمهوري کوزوو', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806050, N'آذربايجان', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806051, N'بورکينافاسو', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806052, N'هنگ کنگ', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806053, N'لیبی', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806054, N'پرو', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9806055, N'سومالي', N'ساير کشورها', 98)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9900000, N'استان سمنان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901000, N'سمنان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901100, N'مرکزي  سمنان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901101, N'سرخه', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901102, N'حومه -  مرکزي  سمنان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901103, N'علا', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901104, N'لاسگرد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901105, N'لاسجرد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901106, N'هفدر', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901107, N'افتدر', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901200, N'مهدي  شهر', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901201, N'شهميرزاد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901202, N'پشتکوه', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901203, N'فولادمحله', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901204, N'چاشم', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9901902, N'خيراباد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902000, N'دامغان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902100, N'مرکزي  دامغان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902101, N'ديباج', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902102, N'حومه -  مرکزي  دامغان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902103, N'برم  قلعه  پايين', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902104, N'دامنکوه', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902105, N'مهماندوست', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902106, N'رودبار', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902200, N'اميرآباد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902201, N'اميريه', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902202, N'قهاب رستاق', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902203, N'فرات', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902204, N'قهاب صرصر', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902205, N'صيداباد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902206, N'تويه  دروار', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902207, N'دروار', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902901, N'ابيداباد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902902, N'حاجي آباد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902903, N'سعداباد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902904, N'اگره', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9902905, N'حسين آباد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903000, N'شاهرود', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903100, N'مرکزي  شاهرود', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903101, N'حومه -  مرکزي  شاهرود', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903102, N'رويان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903103, N'ده  ملا', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903104, N'طرود', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903200, N'بسطام', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903201, N'مجن', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903202, N'کلاته  خيج', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903203, N'کلاته  هاي  غربي', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903204, N'خرقان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903205, N'قلعه  نوخرقان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903300, N'بيارجمند', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903301, N'خانخودي', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903302, N'خوارتوران', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903303, N'زمان اباد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903400, N'ميامي', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903401, N'فرومد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903402, N'کلاته  هاي  شرقي', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903403, N'بکران', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903404, N'نردين', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903405, N'رضوان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903407, N'ري  اباد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903901, N'فرج', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903902, N'قوشه  لرگرمان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903903, N'جيلان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903904, N'خيج', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903905, N'قلعه  نو', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903906, N'ارديان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903907, N'مزج', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9903908, N'نوخرقان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904000, N'گرمسار', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904100, N'مرکزي  گرمسار', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904101, N'حومه -  مرکزي  گرمسار', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904102, N'کردوان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904103, N'لجران', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904200, N'ارادان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904201, N'کهن اباد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904202, N'ياتري', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904203, N'داوراباد', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904300, N'ايوانکي', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904301, N'چشمه  نادي', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904901, N'شاهچراغ', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9904902, N'بندکوه', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9999901, N'اهوان', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9999902, N'دوزهير', N'سمنان', 99)
GO
INSERT [dbo].[tblCityIran] ([fldShahrCode], [fldShahr], [fldOstan], [OstanCode]) VALUES (9999903, N'زيراستاق', N'سمنان', 99)
GO



create TRIGGER [dbo].[tblRizeTolidSetUpdate]
   ON  [dbo].[tblRizeTolid]
   AFTER INSERT,UPDATE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	--declare 
	--declare @code bigint
	--Select @code=fldGroupId from inserted
	update tblRizeTolid Set fldDateUpdate=CONVERT(VARCHAR(19), GETDATE(), 120) 
	where fldShomareTolid in
	(select fldShomareTolid from inserted)

	-- 120
	--select CONVERT(VARCHAR(19), GETDATE(), 120) AS fldDateNow
	--select getdate()
	
	
	

END
GO

create TRIGGER [dbo].[tgDeleteOnlineBargashtAzForoosh]
   on [dbo].[tblBargashtAzForoosh]
after delete 

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


	 Begin Try	
				declare	@fldCode bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='BargashtAzForoosh' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

					
				select @fldCode=fldShomareFactorForoosh from  deleted

				if @fldCode is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCode,'BargashtAzForoosh')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end



    -- Insert statements for trigger here
end catch
END




/****** Object:  Trigger [dbo].[tgInsertUpdateOnlineBargashtAzForoosh]    Script Date: 12/9/2019 11:44:13 AM ******/
SET ANSI_NULLS ON
GO
ALTER TABLE [dbo].[tblBargashtAzForoosh] ENABLE TRIGGER [tgDeleteOnlineBargashtAzForoosh]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlineBargashtAzForoosh]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgInsertUpdateOnlineBargashtAzForoosh]
on [dbo].[tblBargashtAzForoosh]
   AFTER  insert ,Update
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	declare @Code bigint
	Select @Code=fldShomareFactorForoosh from inserted
	update tblBargashtAzForoosh Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldShomareFactorForoosh=@Code

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@Code and fldtype='BargashtAzForoosh'
		--end
END
GO
ALTER TABLE [dbo].[tblBargashtAzForoosh] ENABLE TRIGGER [tgInsertUpdateOnlineBargashtAzForoosh]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnlineBargashtAzKharid]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgDeleteOnlineBargashtAzKharid]
   on [dbo].[tblBargashtAzKharid]
after delete 

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


	 Begin Try	
				declare	@fldCode bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='TblBargashtAzKharid' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

					
				select @fldCode=fldShomareFactorKharid from  deleted

				if @fldCode is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCode,'TblBargashtAzKharid')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end



    -- Insert statements for trigger here
end catch
END


GO
ALTER TABLE [dbo].[tblBargashtAzKharid] ENABLE TRIGGER [tgDeleteOnlineBargashtAzKharid]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlineBargashtAzKharid]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgInsertUpdateOnlineBargashtAzKharid]
on [dbo].[tblBargashtAzKharid]
   AFTER  insert ,Update
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	declare @Code bigint
	Select @Code=fldShomareFactorKharid from inserted
	update tblBargashtAzKharid Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldShomareFactorKharid=@Code

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@Code and fldtype='TblBargashtAzKharid'
		--end
END
GO
ALTER TABLE [dbo].[tblBargashtAzKharid] ENABLE TRIGGER [tgInsertUpdateOnlineBargashtAzKharid]
GO


/****** Object:  Trigger [dbo].[tgDeleteDaftarcheTellOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE trigger [dbo].[tgDeleteDaftarcheTellOnline]
on [dbo].[tblDaftarcheTell]
after delete 
	as


	--Begin Transaction InsertRow
	Begin Try	

			declare	@fldCode bigint,@cnt bigint
			declare @Shomare nvarchar(50)
			set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='daftarchetell' )
	
			if @cnt is null
				set @cnt=1
			else
				set @cnt+=1



			select @fldCode=fldCodeTafzili from  deleted
			select @Shomare=fldShomare from  deleted
			--insert into tblTest7(fld2)
			--	values(@fldCode)
			if @Shomare is not null
				insert into tblDeleteList(id,fldCode,fldtype,fldShomare)
					values(@cnt,@fldCode,'daftarchetell',@Shomare)

end try
Begin Catch
--if @@TRANCOUNT > 0 
--	begin 
--		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
--	end

End Catch
GO
ALTER TABLE [dbo].[tblDaftarcheTell] ENABLE TRIGGER [tgDeleteDaftarcheTellOnline]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdatedaftarchetellOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgInsertUpdatedaftarchetellOnline]
on [dbo].[tblDaftarcheTell]
after  insert ,Update
	as

	declare @Code bigint
	Select @Code=fldCodeTafzili from inserted
	update tblDaftarcheTell Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldCodeTafzili=@Code


	delete tblDeletelist where fldCode=@Code and fldtype='daftarchetell'
		--end
GO
ALTER TABLE [dbo].[tblDaftarcheTell] ENABLE TRIGGER [tgInsertUpdatedaftarchetellOnline]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnlineDaryaft]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgDeleteOnlineDaryaft]
on [dbo].[tblDaryaft]
after delete 
	as
	--IF not EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	--		CREATE TABLE [dbo].[tblKalaOnline](
	--			[fldCodeKala] [bigint] NOT NULL,
	--			[id] [bigint] NOT NULL
	--			)

	--	end

	   --Begin Transaction InsertRow
	      Begin Try	
				declare	@fldCodeKala bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='Daryaft' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

				select @fldCodeKala=fldShomareDaryaft from  deleted

				if @fldCodeKala is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCodeKala,'Daryaft')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end

End Catch



GO
ALTER TABLE [dbo].[tblDaryaft] ENABLE TRIGGER [tgDeleteOnlineDaryaft]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlineDaryaft]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgInsertUpdateOnlineDaryaft]
on [dbo].[tblDaryaft]
after  insert ,Update
	as


	--IF NOT EXISTS(
	--  SELECT *
	--	  FROM INFORMATION_SCHEMA.COLUMNS
	--	  WHERE 
	--		TABLE_NAME = 'tblKala'
	--		AND COLUMN_NAME = 'fldDateUpdate')
	--	BEGIN
	--	  ALTER TABLE tblKala
	--		ADD fldDateUpdate DateTime
	--	END;

	declare @CodeKala bigint
	Select @CodeKala=fldShomareDaryaft from inserted
	update [tblDaryaft]  Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldShomareDaryaft=@CodeKala

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@CodeKala and fldtype='Daryaft'
		--end
GO
ALTER TABLE [dbo].[tblDaryaft] ENABLE TRIGGER [tgInsertUpdateOnlineDaryaft]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnlineForoosh]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgDeleteOnlineForoosh]
   on [dbo].[tblForoosh]
after delete 

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


	 Begin Try	
				declare	@fldCode bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='Foroosh' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

					
				select @fldCode=fldShomareFactorForoosh from  deleted

				if @fldCode is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCode,'Foroosh')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end



    -- Insert statements for trigger here
end catch
END



GO
ALTER TABLE [dbo].[tblForoosh] ENABLE TRIGGER [tgDeleteOnlineForoosh]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlineForoosh]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgInsertUpdateOnlineForoosh]
on [dbo].[tblForoosh]
   AFTER  insert ,Update
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	declare @Code bigint
	Select @Code=fldShomareFactorForoosh from inserted
	update tblForoosh Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldShomareFactorForoosh=@Code

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@Code and fldtype='Foroosh'
		--end
END
GO
ALTER TABLE [dbo].[tblForoosh] ENABLE TRIGGER [tgInsertUpdateOnlineForoosh]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnlineGroupAshkhase]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgDeleteOnlineGroupAshkhase]
   on [dbo].[tblGroupAshkhas]
after delete 

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


	 Begin Try	
				declare	@fldCode bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='GroupAshkhas' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

				select @fldCode=fldGroupId from  deleted

				if @fldCode is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCode,'GroupAshkhas')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end



    -- Insert statements for trigger here
end catch
END


GO
ALTER TABLE [dbo].[tblGroupAshkhas] ENABLE TRIGGER [tgDeleteOnlineGroupAshkhase]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlineGroupAshkhas]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgInsertUpdateOnlineGroupAshkhas]
on [dbo].[tblGroupAshkhas]
   AFTER  insert ,Update
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	declare @Code bigint
	Select @Code=fldGroupId from inserted
	update tblGroupAshkhas Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldGroupId=@Code

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@Code and fldtype='GroupAshkhas'
		--end
END
GO
ALTER TABLE [dbo].[tblGroupAshkhas] ENABLE TRIGGER [tgInsertUpdateOnlineGroupAshkhas]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnlineGroupKala]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgDeleteOnlineGroupKala]
   on [dbo].[tblGroupKala]
after delete 

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


	 Begin Try	
				declare	@fldCode bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='GroupKala' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

				select @fldCode=fldGroupId from  deleted

				if @fldCode is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCode,'GroupKala')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end



    -- Insert statements for trigger here
end catch
END

GO
ALTER TABLE [dbo].[tblGroupKala] ENABLE TRIGGER [tgDeleteOnlineGroupKala]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlineGroupKala]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgInsertUpdateOnlineGroupKala]
on [dbo].[tblGroupKala]
   AFTER  insert ,Update
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	declare @code bigint
	Select @code=fldGroupId from inserted
	update tblGroupKala Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldGroupId=@code

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@code and fldtype='GroupKala'
		--end
END
GO
ALTER TABLE [dbo].[tblGroupKala] ENABLE TRIGGER [tgInsertUpdateOnlineGroupKala]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE trigger [dbo].[tgDeleteOnline]
on [dbo].[tblKala]
after delete 
	as
	--IF not EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	--		CREATE TABLE [dbo].[tblKalaOnline](
	--			[fldCodeKala] [bigint] NOT NULL,
	--			[id] [bigint] NOT NULL
	--			)

	--	end

	   --Begin Transaction InsertRow
	      Begin Try	
				declare	@fldCodeKala bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='kala' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

				select @fldCodeKala=fldCodeKala from  deleted

				if @fldCodeKala is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCodeKala,'kala')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end

End Catch
GO
ALTER TABLE [dbo].[tblKala] ENABLE TRIGGER [tgDeleteOnline]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE trigger [dbo].[tgInsertUpdateOnline]
on [dbo].[tblKala]
after  insert ,Update
	as


	--IF NOT EXISTS(
	--  SELECT *
	--	  FROM INFORMATION_SCHEMA.COLUMNS
	--	  WHERE 
	--		TABLE_NAME = 'tblKala'
	--		AND COLUMN_NAME = 'fldDateUpdate')
	--	BEGIN
	--	  ALTER TABLE tblKala
	--		ADD fldDateUpdate DateTime
	--	END;

	declare @CodeKala bigint
	Select @CodeKala=fldCodeKala from inserted
	update tblKala Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldCodeKala=@CodeKala

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@CodeKala and fldtype='kala'
		--end
		begin try
		declare @cnt bigint
		set @cnt=(select count(fldnumber) as cnt from tblTag  where fldtable='tblkala')
		if @cnt=0
			INSERT INTO tblTag( fldTable, fldNumber)
                                    VALUES        ('tblkala',1)
		else
			update tbltag set fldnumber=fldnumber+1 where fldtable='tblkala'
	end try
	begin catch
		--
	end catch
GO
ALTER TABLE [dbo].[tblKala] ENABLE TRIGGER [tgInsertUpdateOnline]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnlineKharid]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgDeleteOnlineKharid]
   on [dbo].[tblKharid]
after delete 

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


	 Begin Try	
				declare	@fldCode bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='Kharid' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

					
				select @fldCode=fldShomareFactorKharid from  deleted

				if @fldCode is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCode,'Kharid')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end



    -- Insert statements for trigger here
end catch
END



GO
ALTER TABLE [dbo].[tblKharid] ENABLE TRIGGER [tgDeleteOnlineKharid]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlineKharid]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgInsertUpdateOnlineKharid]
on [dbo].[tblKharid]
   AFTER  insert ,Update
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	declare @Code bigint
	Select @Code=fldShomareFactorKharid from inserted
	update tblKharid Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldShomareFactorKharid=@Code

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@Code and fldtype='Kharid'
		--end
END
GO
ALTER TABLE [dbo].[tblKharid] ENABLE TRIGGER [tgInsertUpdateOnlineKharid]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnlineMultiFeeDynamic]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgDeleteOnlineMultiFeeDynamic]
on [dbo].[tblMultiFeeDynamic]
after delete 
	as
	--IF not EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	--		CREATE TABLE [dbo].[tblKalaOnline](
	--			[fldCodeKala] [bigint] NOT NULL,
	--			[id] [bigint] NOT NULL
	--			)

	--	end

	   --Begin Transaction InsertRow
	      Begin Try	

				declare	@fldCode bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='MultiFeeDynamic' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

				select @fldCode=(CONVERT(nvarchar,fldCodeSharh) + CONVERT(nvarchar,fldCodeKala))  from  deleted

				if @fldCode is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCode,'MultiFeeDynamic')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end

End Catch



GO
ALTER TABLE [dbo].[tblMultiFeeDynamic] ENABLE TRIGGER [tgDeleteOnlineMultiFeeDynamic]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlineMultiFeeDynamic]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgInsertUpdateOnlineMultiFeeDynamic]
on [dbo].[tblMultiFeeDynamic]
after  insert ,Update
	as


	--IF NOT EXISTS(
	--  SELECT *
	--	  FROM INFORMATION_SCHEMA.COLUMNS
	--	  WHERE 
	--		TABLE_NAME = 'tblKala'
	--		AND COLUMN_NAME = 'fldDateUpdate')
	--	BEGIN
	--	  ALTER TABLE tblKala
	--		ADD fldDateUpdate DateTime
	--	END;

	declare @Code bigint
	Select @Code= (CONVERT(nvarchar,fldCodeSharh) + CONVERT(nvarchar,fldCodeKala)) from inserted
	update [tblMultiFeeDynamic] Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) 
	where (CONVERT(nvarchar,fldCodeSharh) + CONVERT(nvarchar,fldCodeKala)) = @Code

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@Code and fldtype='MultiFeeDynamic'
		--end
GO
ALTER TABLE [dbo].[tblMultiFeeDynamic] ENABLE TRIGGER [tgInsertUpdateOnlineMultiFeeDynamic]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnlinePardakht]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgDeleteOnlinePardakht]
on [dbo].[tblPardakht]
after delete 
	as
	--IF not EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	--		CREATE TABLE [dbo].[tblKalaOnline](
	--			[fldCodeKala] [bigint] NOT NULL,
	--			[id] [bigint] NOT NULL
	--			)

	--	end

	   --Begin Transaction InsertRow
	      Begin Try	
				declare	@fldCodeKala bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='Pardakht' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

				select @fldCodeKala=fldShomarePardakht from  deleted

				if @fldCodeKala is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCodeKala,'Pardakht')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end

End Catch


GO
ALTER TABLE [dbo].[tblPardakht] ENABLE TRIGGER [tgDeleteOnlinePardakht]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlinePardakht]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgInsertUpdateOnlinePardakht]
on [dbo].[tblPardakht]
after  insert ,Update
	as


	--IF NOT EXISTS(
	--  SELECT *
	--	  FROM INFORMATION_SCHEMA.COLUMNS
	--	  WHERE 
	--		TABLE_NAME = 'tblKala'
	--		AND COLUMN_NAME = 'fldDateUpdate')
	--	BEGIN
	--	  ALTER TABLE tblKala
	--		ADD fldDateUpdate DateTime
	--	END;

	declare @CodeKala bigint
	Select @CodeKala=fldShomarePardakht from inserted
	update tblPardakht  Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldShomarePardakht=@CodeKala

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@CodeKala and fldtype='Pardakht'
		--end
GO
ALTER TABLE [dbo].[tblPardakht] ENABLE TRIGGER [tgInsertUpdateOnlinePardakht]
GO
/****** Object:  Trigger [dbo].[tgDeleteRizeBargastAzForooshOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE trigger [dbo].[tgDeleteRizeBargastAzForooshOnline]
on [dbo].[tblRizeBargashtAzForoosh]
after delete 
	as

	--Begin Transaction InsertRow
	--Begin Try	

	declare	@ShomareForoosh bigint,@cnt bigint

	set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='rizebargashtazforoosh' )
	
	if @cnt is null
		set @cnt=1
	else
		set @cnt+=1

	select @ShomareForoosh=fldShomareFactor from  deleted

	if @ShomareForoosh is not null
		insert into tblDeleteList(id,fldCode,fldtype)
			values(@cnt,@ShomareForoosh,'rizebargashtazforoosh')

--end try
--Begin Catch
----if @@TRANCOUNT > 0 
--	begin 
--		--RollBack Transaction InsertRow;
--		declare @m bigint
--		set @m=1
--	end

--End Catch
GO
ALTER TABLE [dbo].[tblRizeBargashtAzForoosh] ENABLE TRIGGER [tgDeleteRizeBargastAzForooshOnline]
GO
/****** Object:  Trigger [dbo].[tgInsertRizeBargashtAzForooshOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgInsertRizeBargashtAzForooshOnline]
on [dbo].[tblRizeBargashtAzForoosh]
after  insert ,Update
	as


	declare @ShomareForoosh bigint
	Select @ShomareForoosh=fldShomareFactor from inserted
	update tblRizeBargashtAzForoosh Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldShomareFactor=@ShomareForoosh

	delete tblDeletelist where fldCode=@ShomareForoosh and fldtype='rizebargashtazforoosh'
		--end
GO
ALTER TABLE [dbo].[tblRizeBargashtAzForoosh] ENABLE TRIGGER [tgInsertRizeBargashtAzForooshOnline]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnlineRizeBargashtAzKharid]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgDeleteOnlineRizeBargashtAzKharid]
   on [dbo].[tblRizeBargashtAzKharid]
after delete 

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


	 Begin Try	
				declare	@fldCode bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='BargashtAzKharid' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

					
				select @fldCode=fldShomareFactor from  deleted

				if @fldCode is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCode,'BargashtAzKharid')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end



    -- Insert statements for trigger here
end catch
END


GO
ALTER TABLE [dbo].[tblRizeBargashtAzKharid] ENABLE TRIGGER [tgDeleteOnlineRizeBargashtAzKharid]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlineRizeBargashtAzKharid]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create TRIGGER [dbo].[tgInsertUpdateOnlineRizeBargashtAzKharid]
on [dbo].[tblRizeBargashtAzKharid]
   AFTER  insert ,Update
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	declare @Code bigint
	Select @Code=fldShomareFactor from inserted
	update [tblRizeBargashtAzKharid] Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldShomareFactor=@Code

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@Code and fldtype='BargashtAzKharid'
		--end
END
GO
ALTER TABLE [dbo].[tblRizeBargashtAzKharid] ENABLE TRIGGER [tgInsertUpdateOnlineRizeBargashtAzKharid]
GO
/****** Object:  Trigger [dbo].[tgDeleteRizeForooshOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE trigger [dbo].[tgDeleteRizeForooshOnline]
on [dbo].[tblRizeForoosh]
after delete 
	as

	--Begin Transaction InsertRow
	Begin Try	

	declare	@ShomareForoosh bigint,@cnt bigint

	set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='rizeforoosh' )
	
	if @cnt is null
		set @cnt=1
	else
		set @cnt+=1

	select @ShomareForoosh=fldShomareFactor from  deleted

	if @ShomareForoosh is not null
		insert into tblDeleteList(id,fldCode,fldtype)
			values(@cnt,@ShomareForoosh,'rizeforoosh')

end try
Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end

End Catch
GO
ALTER TABLE [dbo].[tblRizeForoosh] ENABLE TRIGGER [tgDeleteRizeForooshOnline]
GO
/****** Object:  Trigger [dbo].[tgInsertRizeForooshOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgInsertRizeForooshOnline]
on [dbo].[tblRizeForoosh]
after  insert ,Update
	as


	declare @ShomareForoosh bigint
	Select @ShomareForoosh=fldShomareFactor from inserted
	update tblRizeForoosh Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldShomareFactor=@ShomareForoosh

	delete tblDeletelist where fldCode=@ShomareForoosh and fldtype='rizeforoosh'
		--end
GO
ALTER TABLE [dbo].[tblRizeForoosh] ENABLE TRIGGER [tgInsertRizeForooshOnline]
GO
/****** Object:  Trigger [dbo].[tgDeleteRizekharidOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE trigger [dbo].[tgDeleteRizekharidOnline]
on [dbo].[tblRizeKharid]
after delete 
	as


	--Begin Transaction InsertRow
	Begin Try	
		declare	@ShomareForoosh bigint,@cnt bigint

		set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='rizekharid' )
	
		if @cnt is null
			set @cnt=1
		else
			set @cnt+=1

		select @ShomareForoosh=fldShomareFactor from  deleted

		if @ShomareForoosh is not null
			insert into tblDeleteList(id,fldCode,fldtype)
				values(@cnt,@ShomareForoosh,'rizekharid')

end try
Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end

End Catch
GO
ALTER TABLE [dbo].[tblRizeKharid] ENABLE TRIGGER [tgDeleteRizekharidOnline]
GO
/****** Object:  Trigger [dbo].[tgInsertRizekharidOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgInsertRizekharidOnline]
on [dbo].[tblRizeKharid]
after  insert ,Update
	as


	declare @ShomareForoosh bigint
	Select @ShomareForoosh=fldShomareFactor from inserted
	update tblRizekharid Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldShomareFactor=@ShomareForoosh

	delete tblDeletelist where fldCode=@ShomareForoosh and fldtype='rizekharid'
		--end
GO
ALTER TABLE [dbo].[tblRizeKharid] ENABLE TRIGGER [tgInsertRizekharidOnline]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnlineSharheFeeDynamic]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgDeleteOnlineSharheFeeDynamic]
on [dbo].[tblSharheFeeDynamic]
after delete 
	as
	--IF not EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	--		CREATE TABLE [dbo].[tblKalaOnline](
	--			[fldCodeKala] [bigint] NOT NULL,
	--			[id] [bigint] NOT NULL
	--			)

	--	end

	   --Begin Transaction InsertRow
	      Begin Try	

				declare	@fldCode bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='SharheFeeDynamic' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

				select @fldCode=fldCodeSharh from  deleted
				
				--delete tblTest7
				--INSERT        iNTO              tblTest7( fld2)
				--VALUES        (@fldCode)		

				if @fldCode is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCode,'SharheFeeDynamic')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end

End Catch


GO
ALTER TABLE [dbo].[tblSharheFeeDynamic] ENABLE TRIGGER [tgDeleteOnlineSharheFeeDynamic]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlineSharheFeeDynamic]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgInsertUpdateOnlineSharheFeeDynamic]
on [dbo].[tblSharheFeeDynamic]
after  insert ,Update
	as


	--IF NOT EXISTS(
	--  SELECT *
	--	  FROM INFORMATION_SCHEMA.COLUMNS
	--	  WHERE 
	--		TABLE_NAME = 'tblKala'
	--		AND COLUMN_NAME = 'fldDateUpdate')
	--	BEGIN
	--	  ALTER TABLE tblKala
	--		ADD fldDateUpdate DateTime
	--	END;

	declare @code bigint
	Select @code= fldCodeSharh from inserted
	update [tblSharheFeeDynamic] Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldCodeSharh =@code

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@code and fldtype='SharheFeeDynamic'
		--end
GO
ALTER TABLE [dbo].[tblSharheFeeDynamic] ENABLE TRIGGER [tgInsertUpdateOnlineSharheFeeDynamic]
GO
/****** Object:  Trigger [dbo].[tgDeleteSanadOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE trigger [dbo].[tgDeleteSanadOnline]
on [dbo].[tblSodooreSanad]
after delete 
	as

	--Begin Transaction InsertRow
	Begin Try	
			declare	@Sanad bigint,@cnt bigint

			set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='sanad' )
	
			if @cnt is null
				set @cnt=1
			else
				set @cnt+=1

			select @Sanad=fldSanad from  deleted

			if @Sanad is not null
				insert into tblDeleteList(id,fldCode,fldtype)
					values(@cnt,@Sanad,'sanad')

	end try
Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end

End Catch
GO
ALTER TABLE [dbo].[tblSodooreSanad] ENABLE TRIGGER [tgDeleteSanadOnline]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateSodooreSanadOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgInsertUpdateSodooreSanadOnline]
on [dbo].[tblSodooreSanad]
after  insert ,Update
	as


	declare @Sanad bigint
	Select @Sanad=fldSanad from inserted
	update tblSodooreSanad Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldSanad=@Sanad

	delete tblDeletelist where fldCode=@Sanad and fldtype='sanad'
		--end
GO
ALTER TABLE [dbo].[tblSodooreSanad] ENABLE TRIGGER [tgInsertUpdateSodooreSanadOnline]
GO
/****** Object:  Trigger [dbo].[tgDeleteTafziliOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE trigger [dbo].[tgDeleteTafziliOnline]
on [dbo].[tblTafzili]
after delete 
	as
	--IF not EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	--		CREATE TABLE [dbo].[tblKalaOnline](
	--			[fldCodeKala] [bigint] NOT NULL,
	--			[id] [bigint] NOT NULL
	--			)

	--	end

	--Begin Transaction InsertRow
	      Begin Try	
					declare	@fldCode bigint,@cnt bigint

					set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='ashkhas' )
	
					if @cnt is null
						set @cnt=1
					else
						set @cnt+=1

					select @fldCode=fldCodeTafzili from  deleted

					if @fldCode is not null
						insert into tblDeleteList(id,fldCode,fldtype)
							values(@cnt,@fldCode,'ashkhas')

			end try
Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end

End Catch
GO
ALTER TABLE [dbo].[tblTafzili] ENABLE TRIGGER [tgDeleteTafziliOnline]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateTafziliOnline]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgInsertUpdateTafziliOnline]
on [dbo].[tblTafzili]
after  insert ,Update
	as


	declare @Code bigint
	Select @Code=fldCodeTafzili from inserted
	update tblTafzili Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldCodeTafzili=@Code

	

	delete tblDeletelist where fldCode=@Code and fldtype='ashkhas'

	begin try
		update tbltag set fldnumber=fldnumber+1 where fldtable='tbltafzili'
	end try
	begin catch
		--
	end catch
GO
ALTER TABLE [dbo].[tblTafzili] ENABLE TRIGGER [tgInsertUpdateTafziliOnline]
GO
/****** Object:  Trigger [dbo].[tgDeleteOnlinetblVahed]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create TRIGGER [dbo].[tgDeleteOnlinetblVahed]
   on [dbo].[tblVahed]
after delete 

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


	 Begin Try	
				declare	@fldCode bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='Vahed' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

				select @fldCode=ID  from  deleted

				if @fldCode is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldCode,'Vahed')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end



    -- Insert statements for trigger here
end catch
END
GO
ALTER TABLE [dbo].[tblVahed] ENABLE TRIGGER [tgDeleteOnlinetblVahed]
GO
/****** Object:  Trigger [dbo].[tgInsertUpdateOnlinetblVahed]    Script Date: 4/26/2020 3:08:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[tgInsertUpdateOnlinetblVahed]
on [dbo].[tblVahed]
   AFTER  insert ,Update
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
	declare @code bigint
	Select @code=ID from inserted
	update tblVahed Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where ID=@code

	--IF  EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES 
 --          WHERE TABLE_NAME = N'tblKalaOnline')
	--	BEGIN
	delete tblDeletelist where fldCode=@code and fldtype='Vahed'
		--end
END
GO
ALTER TABLE [dbo].[tblVahed] ENABLE TRIGGER [tgInsertUpdateOnlinetblVahed]
GO



create trigger [dbo].[tgDeleteOnlineHavale]
on [dbo].[tblHavaleGoroohi]
after delete 
	as
	      Begin Try	
				declare	@fldShomareHavale bigint,@cnt bigint

				set @cnt=(Select count(fldCode) from tblDeleteList where fldtype='havale' )
	
				if @cnt is null
					set @cnt=1
				else
					set @cnt+=1

				select @fldShomareHavale=fldShomareHavale from  deleted

				if @fldShomareHavale is not null
					insert into tblDeleteList(id,fldCode,fldtype)
						values(@cnt,@fldShomareHavale,'havale')

			End Try

Begin Catch
--if @@TRANCOUNT > 0 
	begin 
		--RollBack Transaction InsertRow;
		declare @m bigint
		set @m=1
	end

End Catch
GO
/****** Object:  Trigger [dbo].[tgInsertHavaleUpdateOnline]    Script Date: 9/7/2023 1:01:23 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgInsertHavaleUpdateOnline]
on [dbo].[tblHavaleGoroohi]
after  insert ,Update
	as


	declare @fldShomareHavale bigint
	Select @fldShomareHavale=fldShomareHavale from inserted
	update tblHavaleGoroohi Set fldDateUpdate=(Select CONVERT(VARCHAR(19), GETDATE(), 120)) where fldShomareHavale=@fldShomareHavale

	delete tblDeletelist where fldCode=@fldShomareHavale and fldtype='havale'
		--end
GO
