· 8 years ago · Jun 14, 2018, 06:28 AM
1if @nPriceList2006 is not null and @nPriceList2006 <> 0
2 BEGIN
3 -- -- -- -- -- запиÑÑŒ в PriceList
4 -- insert into History (Hi_date, Hi_text, Hi_SVKey) values (GetDate(), 'Ðачало раÑчета', @nPriceTourKey)
5 delete from dbo.pricelist where pl_trkey=@TrKey
6 CREATE TABLE #TP_Lists (
7 [xTI_Key] [int] PRIMARY KEY NOT NULL ,
8 [xTI_FirstHdKey] [int] NOT NULL ,
9 [xTI_FirstHrKey] [int] NOT NULL ,
10 [xTI_FirstPnKey] [int] NOT NULL ,
11 [xTI_Days] [int] NOT NULL ,
12 [xTI_PNCode] varchar(3) NULL ,
13 [xTI_ACMain] [int] ,
14 [xTI_ACNRealPlaces] [int] ,
15 [xTI_ACNMenExBed] [int] ,
16 [xTI_ACAgeFrom] [int] ,
17 [xTI_ACName] varchar(30) ,
18 [xTI_RCKey] [int] NOT NULL ,
19 [xTI_RMKey] [int] NOT NULL ,
20 [xTI_RCName] varchar(35) ,
21 [xTI_RMName] varchar(35) ,
22 [xTI_HDStars] varchar(12) ,
23 [xTI_HDName] varchar(60) ,
24 [xTI_HDHTTP] varchar(128) ,
25 [xTI_HDCNKey] [int],
26 [xTI_HDCTKey] [int],
27 [xTI_HDRSKey] [int],
28 [xTI_RSName] varchar(20),
29 [xTI_CTName] varchar(50),
30
31 [xti_su1] varchar(824),
32 [xti_su2] varchar(824),
33 [xti_CityArr] [int],
34 [xti_sh1] varchar(824),
35 [xti_st1] varchar(824),
36 [xti_st2] varchar(824),
37 [xti_ss1] varchar(824),
38 [xti_sv1] varchar(824),
39 [xti_sd1] varchar(824),
40 [xti_u] varchar(824),
41
42 [xti_chkey] int,
43 [xti_chbackkey] int,
44 [xti_hdday] int,
45 [xti_hdnights] int,
46 [xti_chday] int,
47 [xti_ctkeyto] int,
48 [xti_chpkkey] int,
49 [xti_chprkey] int,
50 [xti_chbackday] int,
51 [xti_chbackpkkey] int,
52 [xti_chbackprkey] int
53 ) ON [PRIMARY]
54 DELETE FROM #TP_Lists
55 INSERT INTO #TP_Lists (xTI_Key, xTI_FirstHdKey, xTI_FirstHrKey, xTI_FirstPnKey, xTI_Days,
56 xTI_ACMain, xTI_ACNRealPlaces, xTI_ACNMenExBed, xTI_ACAgeFrom, xTI_ACName,
57 xTI_RCKey, xTI_RMKey,
58 xTI_HDStars, xTI_HDName, xTI_HDCNKey, xTI_HDCTKey, xTI_HDRSKey, xTI_HDHTTP
59 )
60 select TI_Key, TI_FirstHdKey, TI_FirstHrKey, TI_FirstPnKey, TI_Days,
61 AC_Main, AC_NRealPlaces, AC_NMenExBed, AC_AgeFrom, AC_Name,
62 HR_RCKey, HR_RMKey,
63 HD_Stars, HD_Name, HD_CNKey, HD_CTKey, HD_RSKey, HD_HTTP
64 from dbo.TP_Lists,
65 dbo.HotelRooms,
66 dbo.AccmdMenType,
67 dbo.HotelDictionary
68 where TI_TOKey = @nPriceTourKey
69 and HR_Key = TI_FirstHrKey
70 and AC_Key = HR_ACKey
71 and HD_Key = TI_FirstHdKey
72
73 update #TP_Lists Set xTI_RSName = (Select RS_Name From dbo.Resorts Where RS_Key = xTI_HDRSKey)
74 update #TP_Lists Set xTI_PNCode = (Select PN_Code From dbo.Pansion Where PN_Key = xTI_FirstPnKey)
75 update #TP_Lists Set xTI_RCName = (Select RC_Name From dbo.RoomsCategory Where RC_Key = xTI_RCKey)
76 update #TP_Lists Set xTI_RMName = (Select RM_Name From dbo.Rooms Where RM_Key = xTI_RMKey)
77 update #TP_Lists Set xTI_CTName = (Select CT_Name From dbo.CityDictionary Where CT_Key = xTI_HDCTKey)
78
79 update #TP_Lists Set xti_su2 = (
80 Select TOP 1 LTRIM(STR(TS_Day)) + ',' + LTRIM(STR(TS_Code)) + ',' + LTRIM(STR(TS_SubCode1)) + ',' + LTRIM(STR(TS_SubCode2)) + ',' + LTRIM(STR(TS_CtKey)) + ',' + LTRIM(STR(TS_Attribute)) + ',' + LTRIM(STR(TS_OpPacketKey)) + ',' + LTRIM(STR(TS_Men)) + ',' + LTRIM(STR(TS_OpPartnerKey))
81 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
82 and TS_SvKey = 1 and TS_Day != 1)
83
84 update #TP_Lists Set xti_chbackkey = (
85 Select TOP 1 TS_Code
86 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
87 and TS_SvKey = 1 and TS_Day != 1)
88
89 update #TP_Lists Set xti_chbackday = (
90 Select TOP 1 TS_Day
91 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
92 and TS_SvKey = 1 and TS_Day != 1)
93
94 update #TP_Lists Set xti_chbackpkkey = (
95 Select TOP 1 TS_OpPacketKey
96 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
97 and TS_SvKey = 1 and TS_Day != 1)
98
99 update #TP_Lists Set xti_chbackprkey = (
100 Select TOP 1 TS_OpPartnerKey
101 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
102 and TS_SvKey = 1 and TS_Day != 1)
103
104/*
105 xti_chbackkey = TS_Code,
106 xti_chbackday = TS_Day,
107 xti_chbackpkkey = TS_OpPacketKey,
108 xti_chbackprkey = TS_OpPartnerKey
109*/
110
111 update #TP_Lists Set xti_su1 = (
112 Select TOP 1 LTRIM(STR(TS_Day)) + ',' + LTRIM(STR(TS_Code)) + ',' + LTRIM(STR(TS_SubCode1)) + ',' + LTRIM(STR(TS_SubCode2)) + ',' + LTRIM(STR(TS_CtKey)) + ',' + LTRIM(STR(TS_Attribute)) + ',' + LTRIM(STR(TS_OpPacketKey)) + ',' + LTRIM(STR(TS_Men)) + ',' + LTRIM(STR(TS_OpPartnerKey))
113 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
114 and TS_SvKey = 1 and TS_Day = 1)
115
116 update #TP_Lists Set xti_chkey = (
117 Select TOP 1 TS_Code
118 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
119 and TS_SvKey = 1 and TS_Day = 1)
120
121 update #TP_Lists Set xti_chday = (
122 Select TOP 1 TS_Day
123 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
124 and TS_SvKey = 1 and TS_Day = 1)
125
126 update #TP_Lists Set xti_ctkeyto = (
127 Select TOP 1 TS_CtKey
128 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
129 and TS_SvKey = 1 and TS_Day = 1)
130
131 update #TP_Lists Set xti_chpkkey = (
132 Select TOP 1 TS_OpPacketKey
133 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
134 and TS_SvKey = 1 and TS_Day = 1)
135
136 update #TP_Lists Set xti_chprkey = (
137 Select TOP 1 TS_OpPartnerKey
138 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
139 and TS_SvKey = 1 and TS_Day = 1)
140
141/*
142 xti_chkey = TS_Code,
143 xti_chday = TS_Day,
144 xti_ctkeyto = TS_CtKey,
145 xti_chpkkey = TS_OpPacketKey,
146 xti_chprkey = TS_OpPartnerKey
147*/
148
149 update #TP_Lists Set xti_CityArr = (
150 Select TOP 1 TS_SubCode2
151 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
152 and TS_SvKey = 1 and TS_Day = 1)
153
154 update #TP_Lists Set xti_sh1 = (
155 Select TOP 1 LTRIM(STR(TS_Day)) + ',' + LTRIM(STR(TS_Code)) + ',' + LTRIM(STR(TS_SubCode1)) + ',' + LTRIM(STR(TS_SubCode2)) + ',' + LTRIM(STR(TS_Days)) + ',' + LTRIM(STR(TS_CtKey)) + ',' + LTRIM(STR(TS_Attribute)) + ',' + LTRIM(STR(TS_OpPacketKey)) + ',' + LTRIM(STR(TS_Men)) + ',' + LTRIM(STR(TS_OpPartnerKey))
156 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
157 and TS_SvKey = 3)
158
159 update #TP_Lists Set xti_hdday = (
160 Select TOP 1 TS_Day
161 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
162 and TS_SvKey = 3)
163
164 update #TP_Lists Set xti_hdnights = (
165 Select TOP 1 TS_Days
166 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
167 and TS_SvKey = 3)
168
169 update #TP_Lists Set xti_st2 = (
170 Select TOP 1 LTRIM(STR(TS_Day)) + ',' + LTRIM(STR(TS_Code)) + ',' + LTRIM(STR(TS_SubCode1)) + ',' + LTRIM(STR(TS_CtKey)) + ',' + LTRIM(STR(TS_Attribute)) + ',' + LTRIM(STR(TS_OpPacketKey)) + ',' + LTRIM(STR(TS_Men)) + ',' + LTRIM(STR(TS_OpPartnerKey))
171 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
172 and TS_SvKey = 2 and TS_Day != 1)
173
174 update #TP_Lists Set xti_st1 = (
175 Select TOP 1 LTRIM(STR(TS_Day)) + ',' + LTRIM(STR(TS_Code)) + ',' + LTRIM(STR(TS_SubCode1)) + ',' + LTRIM(STR(TS_CtKey)) + ',' + LTRIM(STR(TS_Attribute)) + ',' + LTRIM(STR(TS_OpPacketKey)) + ',' + LTRIM(STR(TS_Men)) + ',' + LTRIM(STR(TS_OpPartnerKey))
176 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
177 and TS_SvKey = 2 and TS_Day = 1)
178
179 update #TP_Lists Set xti_ss1 = (
180 Select TOP 1 LTRIM(STR(TS_Day)) + ',' + LTRIM(STR(TS_Code)) + ',' + LTRIM(STR(TS_Days)) + ',' + LTRIM(STR(TS_Attribute)) + ',' + LTRIM(STR(TS_OpPacketKey)) + ',' + LTRIM(STR(TS_Men)) + ',' + LTRIM(STR(TS_SubCode1)) + ',' + LTRIM(STR(TS_SubCode2)) + ',' + LTRIM(STR(TS_OpPartnerKey))
181 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
182 and TS_SvKey = 6)
183
184 update #TP_Lists Set xti_sv1 = (
185 Select TOP 1 LTRIM(STR(TS_Day)) + ',' + LTRIM(STR(TS_Code)) + ',' + LTRIM(STR(TS_Days)) + ',' + LTRIM(STR(TS_Attribute)) + ',' + LTRIM(STR(TS_OpPacketKey)) + ',' + LTRIM(STR(TS_Men)) + ',' + LTRIM(STR(TS_OpPartnerKey))
186 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
187 and TS_SvKey = 5)
188
189 update #TP_Lists Set xti_sd1 = (
190 Select TOP 1 LTRIM(STR(TS_Day)) + ',' + LTRIM(STR(TS_Code)) + ',' + LTRIM(STR(TS_SubCode1)) + ',' + LTRIM(STR(TS_SubCode2)) + ',' + LTRIM(STR(TS_Days)) + ',' + LTRIM(STR(TS_CtKey)) + ',' + LTRIM(STR(TS_Attribute)) + ',' + LTRIM(STR(TS_OpPacketKey)) + ',' + LTRIM(STR(TS_Men)) + ',' + LTRIM(STR(TS_OpPartnerKey))
191 From dbo.TP_ServiceLists, dbo.TP_Services Where TL_TOKey=@nPriceTourKey and TL_TIKey=xTI_Key and TS_Key=TL_TSKey
192 and TS_SvKey = 8)
193
194 update #TP_Lists Set xti_u = 'MID=' + LTRIM(STR(@TrKey)) + '&' + 'DAY=' + LTRIM(STR(xTI_Days)) + '&' + 'H=1&H1=' + xti_sh1 + '&'
195 update #TP_Lists Set xti_u = xti_u + 'U=2&' + 'U1=' + xti_su1 + '&' + 'U2=' + xti_su2 + '&'
196 where xti_su2 != '' and xti_su2 is not null
197 update #TP_Lists Set xti_u = xti_u + 'U=1&' + 'U1=' + xti_su1 + '&'
198 where (xti_su2 = '' or xti_su2 is null) and xti_su1 != '' and xti_su1 is not null
199 update #TP_Lists Set xti_u = xti_u + 'T=2&' + 'T1=' + xti_st1 + '&' + 'T2=' + xti_st2 + '&'
200 where xti_st2 != '' and xti_st2 is not null
201 update #TP_Lists Set xti_u = xti_u + 'T=1&' + 'T1=' + xti_st1 + '&'
202 where (xti_st2 = '' or xti_st2 is null) and xti_st1 != '' and xti_st1 is not null
203
204 update #TP_Lists Set xti_u = 'S=1&' + xti_u + 'S1=' + xti_ss1 + '&'
205 where xti_ss1 != '' and xti_ss1 is not null
206 update #TP_Lists Set xti_u = 'V=1&' + xti_u + 'V1=' + xti_sv1 + '&'
207 where xti_sv1 != '' and xti_sv1 is not null
208 update #TP_Lists Set xti_u = 'D=1&' + xti_u + 'D1=' + xti_sd1 + '&'
209 where xti_sd1 != '' and xti_sd1 is not null
210
211 select @TPkeyMax = MAX(xtp_key),
212 @TPkeyMin = MIN(xtp_key)
213 from #tp_prices
214
215 Set @NumPrices = @TPkeyMax - @TPkeyMin + 1 -- определÑем Ñколько нам понадобитÑÑ Ñделать запиÑей в таблицу pricelist
216 declare @nPriceListKeyMax int -- макÑимально возможный ключ PriceList, который можно иÑпользовать
217 exec GetNKeys 'PRICELIST', @NumPrices, @nPriceListKeyMax output
218 declare @nDeltaTP_Price_PriceList int -- разница в ключах между таблицами TP_Price и PriceList
219 Set @nDeltaTP_Price_PriceList = (@nPriceListKeyMax - @NumPrices + 1) - @TPkeyMin
220 declare @sURL varchar(250) -- ÑÑылка, у Ð’Ð¸Ñ‚Ð°Ð»Ð¸Ñ Ð“Ð¾Ð»Ð¾Ð²Ñ‡ÐµÐ½ÐºÐ¾ называлаÑÑŒ @u
221 declare @sTLName varchar(160)
222 declare @sTLWebHTTP varchar(128)
223 select @sTLName = TL_Name, @sTLWebHTTP = TL_WebHTTP from dbo.TurList where TL_key = @TrKey
224
225 -- начало. удаление похожих цен
226 if @nPLNotDeleted = 0
227 delete from dbo.pricelist where exists (
228 select xTI_Key
229 from #tp_lists, TP_TurDates
230 where xTI_FirstHdKey = pl_hdkey_first and xTI_FirstHrKey = PL_ROOM
231 and xTI_FirstPnKey = PL_PNKEY and xTI_Days = PL_NDays and xti_CityArr = PL_CITYARR
232 and TD_TOKey = @nPriceTourKey
233 and TD_Date = PL_DATEBEG)
234 -- конец. удаление похожих цен
235
236 while @TPkeyMin <= @TPkeyMax
237 BEGIN
238 begin tran tEnd
239 insert into dbo.PRICELIST (
240 PL_KEY, PL_TI, PL_TO, PL_TP,
241 PL_CREATOR, PL_DATEBEG, PL_DATEEND, PL_BRUTTO,
242 PL_TRKEY, PL_NDays, PL_HDKEY_FIRST, PL_ROOM,
243 PL_PANSION, PL_Category, PL_Main, PL_ACNMENAD,
244 PL_ACNMENEXB, PL_ACAGEFROM1, PL_STARS, PL_HDNAME,
245 PL_CNKEY, PL_HDCTKEY, PL_HDRSKEY, PL_URL,
246 PL_CITYARR, PL_TLWEBHTTP, PL_HDHTTP, PL_ACNAME,
247 PL_RCNAME, PL_RMNAME, PL_RSNAME, PL_RMKEY,
248 PL_PNKEY, PL_TLNAME, PL_CTNAME, PL_chkey,
249 PL_chbackkey, PL_hdday, PL_hdnights, PL_chday,
250 PL_ctkeyto, PL_chpkkey, PL_chprkey, PL_chbackday,
251 PL_chbackpkkey, PL_chbackprkey )
252 select @nDeltaTP_Price_PriceList + xtp_key, xTP_TIKey, xtp_tokey, xtp_key,
253 0, xtp_dateBegin, xtp_DateEnd, xTP_Gross,
254 @TrKey, xTI_Days, xTI_FirstHdKey, xTI_FirstHrKey, --@TrKey объÑвлена в коде выше
255 xTI_PNCode, xTI_RCKey, xTI_ACMain, xTI_ACNRealPlaces,
256 xTI_ACNMenExBed, xTI_ACAgeFrom, xTI_HDStars, xTI_HDName,
257 xTI_HDCNKey, xTI_HDCTKey, xTI_HDRSKey, xti_u,
258 xti_CityArr, @sTLWebHTTP, xTI_HDHTTP, xTI_ACName,
259 xTI_RCName, xTI_RMName, xTI_RSName, xTI_RMKey,
260 xTI_FirstPnKey, @sTLName, xTI_CTName, xti_chkey,
261 xti_chbackkey, xti_hdday, xti_hdnights, xti_chday,
262 xti_ctkeyto, xti_chpkkey, xti_chprkey, xti_chbackday,
263 xti_chbackpkkey, xti_chbackprkey
264 from #tp_prices, #tp_lists
265 where xTP_TIKey = xTI_Key
266 and xtp_key between @TPkeyMin and @TPkeyMin + @nRowPart
267 commit tran tEnd
268 Set @TPkeyMin = @TPkeyMin + @nRowPart + 1
269 END
270 -- exec ttsCreatePrice123456Table @TrKey
271 -- insert into History (Hi_date, Hi_text, Hi_SVKey) values (GetDate(), 'Скопировали в PriceList123.. и закончили раÑчет', @nPriceTourKey)
272 -- окончание запиÑи в PriceList
273 -- exec ttsLoadAllTpPrice @TrKey
274 END
275 declare @bExist int
276 exec isObjectExist 'mwReplTours', null, 'T' , @bExist out
277 if @bExist = 1
278 insert into dbo.mwReplTours (rt_trkey) values (@TrKey)
279
280 Set @nTotalProgress = 100
281 update tp_tours set to_progress = @nTotalProgress where to_key = @nPriceTourKey
282 set DATEFIRST @nDateFirst
283 Return 0
284END
285SET QUOTED_IDENTIFIER OFF