1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
| Private Sub BgWorker_DoWork(sender As Object, e As DoWorkEventArgs) Handles bgWorker.DoWork
'здесь начинаю формировать выписку
If ComboBox1.SelectedValue <> 0 Then
Dim SqlRsh As String = " AND IDAccountOrganizer=" & ComboBox1.SelectedValue
' сальдо на начало
Dim SaldoNach As Decimal = getDec("SELECT((SELECT SUM(AmountOrder) As Postupl FROM paymentorder
WHERE IDDirectionOrder=1 AND DatePaymentOrder<'" & Format(DateTimePicker1.Value, "yyyy-MM-dd") & "'" & SqlRsh &
")-(SELECT SUM(AmountOrder) As Spisan FROM paymentorder WHERE IDDirectionOrder=2 AND
DatePaymentOrder<'" & Format(DateTimePicker1.Value, "yyyy-MM-dd") & "'" & SqlRsh & ")) AS SaldoNach FROM paymentorder")
' Обороты за период
Dim debet As Decimal = getDec("SELECT SUM(AmountOrder) As Postupl FROM paymentorder WHERE IDDirectionOrder=1 AND DatePaymentOrder>='" & Format(DateTimePicker1.Value, "yyyy-MM-dd") & "' AND DatePaymentOrder<='" & Format(DateTimePicker2.Value, "yyyy-MM-dd") & "' " & SqlRsh)
Dim Kredit As Decimal = getDec("SELECT SUM(AmountOrder) As Postupl FROM paymentorder WHERE IDDirectionOrder=2 AND DatePaymentOrder>='" & Format(DateTimePicker1.Value, "yyyy-MM-dd") & "' AND DatePaymentOrder<='" & Format(DateTimePicker2.Value, "yyyy-MM-dd") & "' " & SqlRsh)
' Сальдо на конец периода
Dim SaldoCon As Decimal = SaldoNach - Kredit + debet
Dim PrevDate As String = getScalar("SELECT MAX(DatePaymentOrder) FROM paymentorder WHERE DatePaymentOrder<'" & Format(DateTimePicker1.Value, "yyyy-MM-dd") & "' " & SqlRsh)
'документы оборота за период
Dim DocObr As DataTable = getDataTable("SELECT * FROM paymentorder WHERE DatePaymentOrder>='" & Format(DateTimePicker1.Value, "yyyy-MM-dd") & "' AND DatePaymentOrder<='" & Format(DateTimePicker2.Value, "yyyy-MM-dd") & "' " & SqlRsh, "DocObr")
Dim tr As String = ""
If DocObr.Rows.Count = 0 Then
tr = "<tr height=51 style='height:38.25pt'>
<td height=51 class=xl70 style='height:38.25pt;border-top:none'></td>
<td class=xl71 style='border-top:none;border-left:none'></td>
<td class=xl72 style='border-top:none;border-left:none'></td>
<td class=xl65 align=right style='border-top:none;border-left:none'></td>
<td class=xl65 align=right style='border-top:none;border-left:none'></td>
<td class=xl73 width=141 style='border-top:none;border-left:none;width:106pt'><br>
<br>
</td>
<td class=xl69 style='border-top:none;border-left:none'></td>
</tr>"
End If
For i As Integer = 0 To DocObr.Rows.Count - 1
'распределяем сумму по дебету кредету
Dim dbt As String = ""
Dim kred As String = ""
If DocObr(i)("IDDirectionOrder") = 1 Then
kred = Format(DocObr(i)("AmountOrder"), "#,##0.00")
Else
dbt = Format(DocObr(i)("AmountOrder"), "#,##0.00")
End If
' получаем данные по контрагенту
Dim dtContr As DataTable = getDataTable("SELECT NameContractor, INNContractor,
(SELECT Rsch FROM accountcontractors WHERE IDAccountContractor=" & DocObr(i)("IDAccountContr") & ") As AccauntContr
FROM `contractors` WHERE IDContractor=" & DocObr(i)("IDContr"), "dtContr")
Dim cont As String = "ИНН " & dtContr(0)("INNContractor") & "<br>" & "Р/сч.№ " & dtContr(0)("AccauntContr") & "<br>" & dtContr(0)("NameContractor")
tr = tr & "<tr height=51 style='height:38.25pt'>
<td height=51 class=xl70 style='height:38.25pt;border-top:none'>" & DocObr(i)("NumberPaymentOrder") & "</td>
<td class=xl71 style='border-top:none;border-left:none'>" & DocObr(i)("Wagetype") & "</td>
<td class=xl72 style='border-top:none;border-left:none'>" & DocObr(i)("DatePaymentOrder") & "</td>
<td class=xl65 align=right style='border-top:none;border-left:none'>" & dbt & "</td>
<td class=xl65 align=right style='border-top:none;border-left:none'>" & kred & "</td>
<td class=xl73 width=141 style='border-top:none;border-left:none;width:106pt'>" & cont & "</td>
<td class=xl69 style='border-top:none;border-left:none'>" & DocObr(i)("PurposePayment") & "</td>
</tr>"
Next
Dim BodyHtml As String = "
<html xmlns:v=""urn:schemas-Microsoft - com: vml""
xmlns:o=""urn: schemas-Microsoft - com: office : office""
xmlns:x=""urn: schemas-Microsoft - com: office : excel""
xmlns=""http://www.w3.org/TR/REC-html40"">
<head>
<meta http-equiv=Content-Type content=""text/html; charset=windows-1251"">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content=""Microsoft Excel 12"">
<style>
<!--table
{mso-displayed-decimal-separator:"" \,"";
mso-displayed-thousand-separator:"" "";}
@page
{margin:.75in .7in .75in .7in;
mso-header-margin:.3in;
mso-footer-margin:.3in;}
tr
{mso-height-source:auto;}
col
{mso-width-source:auto;}
br
{mso-data-placement:same-cell;}
.style0
{mso-number-format:General;
text-align:general;
vertical-align:bottom;
white-space:nowrap;
mso-rotate:0;
mso-background-source:auto;
mso-pattern:auto;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:204;
border:none;
mso-protection:locked visible;
mso-style-name:Обычный;
mso-style-id:0;}
td
{mso-style-parent:style0;
padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:204;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:none;
mso-background-source:auto;
mso-pattern:auto;
mso-protection:locked visible;
white-space:nowrap;
mso-rotate:0;}
.xl65
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
mso-number-format:Fixed;
border:.5pt solid windowtext;}
.xl66
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
text-align:center;}
.xl67
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;}
.xl68
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
mso-number-format:Fixed;
text-align:right;
border:.5pt solid windowtext;}
.xl69
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
text-align:left;
border:.5pt solid windowtext;}
.xl70
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
mso-number-format:"" \@"";
text-align:left;
border:.5pt solid windowtext;}
.xl71
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
mso-number-format:"" \@"";
text-align:center;
border:.5pt solid windowtext;}
.xl72
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
mso-number-format:""Short Date"";
text-align:center;
border:.5pt solid windowtext;}
.xl73
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
text-align:left;
border:.5pt solid windowtext;
white-space:normal;}
.xl74
{mso-style-parent:style0;
font-size:10.0pt;
font-weight:700;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
text-align:center;
vertical-align:middle;
border:.5pt solid windowtext;
white-space:normal;}
.xl75
{mso-style-parent:style0;
font-size:10.0pt;
font-weight:700;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
text-align:center;
vertical-align:middle;
border:.5pt solid windowtext;}
.xl76
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
text-align:center;
border-top:none;
border-right:none;
border-bottom:.5pt solid windowtext;
border-left:none;}
.xl77
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
text-align:left;
border-top:none;
border-right:none;
border-bottom:.5pt solid windowtext;
border-left:none;}
.xl78
{mso-style-parent:style0;
font-size:10.0pt;
font-family:""Times New Roman"", serif;
mso-font-charset:204;
mso-number-format:Fixed;
text-align:left;
border-top:none;
border-right:none;
border-bottom:.5pt solid windowtext;
border-left:none;}
-->
</style>
</head>
<body link=blue vlink=purple class=xl67>
<table border=0 cellpadding=0 cellspacing=0 width=609 style='border-collapse:
collapse;table-layout:auto;width:458pt'>
<col class=xl67 width=67 style='mso-width-source:userset;mso-width-alt:2450;
width:50pt'>
<col class=xl67 width=24 style='mso-width-source:userset;mso-width-alt:877;
width:18pt'>
<col class=xl67 width=67 style='mso-width-source:userset;mso-width-alt:2450;
width:50pt'>
<col class=xl67 width=78 span=2 style='mso-width-source:userset;mso-width-alt:
2852;width:59pt'>
<col class=xl67 width=141 style='mso-width-source:userset;mso-width-alt:5156;
width:106pt'>
<col class=xl67 width=154 style='mso-width-source:userset;mso-width-alt:5632;
width:116pt'>
<tr height=17 style='height:12.75pt'>
<td colspan=7 height=17 class=xl66 width=609 style='height:12.75pt;
width:458pt'>" & getScalar("SELECT Bank FROM accountorganizer WHERE IDAccountOrganizer=" & ComboBox1.SelectedValue) & "</td>
</tr>
<tr height=17 style='height:12.75pt'>
<td colspan=7 height=17 class=xl66 style='height:12.75pt'>Выписка по счету № " & ComboBox1.Text & "
</td>
</tr>
<tr height=17 style='height:12.75pt'>
<td colspan=7 height=17 class=xl66 style='height:12.75pt'>за период с " & Format(DateTimePicker1.Value, "dd-MM-yyyy") & "
г. по " & Format(DateTimePicker2.Value, "dd-MM-yyyy") & " г. включительно</td>
</tr>
<tr height=17 style='height:12.75pt'>
<td height=17 colspan=7 class=xl66 style='height:12.75pt;mso-ignore:colspan'></td>
</tr>
<tr height=17 style='height:12.75pt'>
<td colspan=3 height=17 class=xl77 style='height:12.75pt'>Входящий остаток:
</td>
<td class=xl78>" & Format(SaldoNach, "#,##0.00") & "</td>
<td class=xl78> </td>
<td colspan=2 class=xl76>Дата предыдущей операции: " & PrevDate & " г.</td>
</tr>
<tr height=34 style='height:25.5pt'>
<td height=34 class=xl74 width=67 style='height:25.5pt;border-top:none;
width:50pt'>Номер документа</td>
<td class=xl74 width=24 style='border-top:none;border-left:none;width:18pt'>ВО</td>
<td class=xl74 width=67 style='border-top:none;border-left:none;width:50pt'>Дата
операции</td>
<td class=xl74 width=78 style='border-top:none;border-left:none;width:59pt'>Дебет</td>
<td class=xl74 width=78 style='border-top:none;border-left:none;width:59pt'>Кредет</td>
<td class=xl74 width=141 style='border-top:none;border-left:none;width:106pt'>Реквизиты
контрагента</td>
<td class=xl74 width=154 style='border-top:none;border-left:none;width:116pt'>Основание
операции</td>
</tr>" & tr &
"<tr height=17 style='height:12.75pt'>
<td height=17 colspan=7 class=xl67 style='height:12.75pt;mso-ignore:colspan'></td>
</tr>
<tr height=17 style='height:12.75pt'>
<td colspan=3 rowspan=2 height=34 class=xl75 style='height:25.5pt'>Входящий
остаток</td>
<td colspan=3 class=xl75 style='border-left:none'>Оборот за период с " & Format(DateTimePicker1.Value, "dd-MM-yyyy") & "
г. по " & Format(DateTimePicker2.Value, "dd-MM-yyyy") & " г.</td>
<td rowspan=2 class=xl75>Исходящий остаток</td>
</tr>
<tr height=17 style='height:12.75pt'>
<td colspan=2 height=17 class=xl75 style='height:12.75pt;border-left:none'>Дебет</td>
<td class=xl75 style='border-top:none;border-left:none'>Кредет</td>
</tr>
<tr height=17 style='height:12.75pt'>
<td colspan=3 height=17 class=xl68 style='height:12.75pt'>" & Format(SaldoNach, "#,##0.00") & "</td>
<td colspan=2 class=xl68 style='border-left:none'>" & Format(Kredit, "#,##0.00") & "</td>
<td class=xl68 style='border-top:none;border-left:none'>" & Format(debet, "#,##0.00") & "</td>
<td class=xl68 style='border-top:none;border-left:none'>" & Format(SaldoCon, "#,##0.00") & "</td>
</tr>
</table>
</body>
</html>
"
e.Result = BodyHtml
Else
End If
End Sub
Private Sub BgWorker_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles bgWorker.RunWorkerCompleted
Dim BodyHtml As String = CType(e.Result, String)
'здесь показываю выписку
WebBrowser1.Document.OpenNew(False)
WebBrowser1.Document.Write(BodyHtml)
'WebBrowser1.DocumentText = BodyHtml
WebBrowser1.Refresh()
'WebBrowser1.Update()
ToolStripButton3.Enabled = True
End Sub
Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click
Dim BodyHtml As String = "<!DOCTYPE html>
<html lang='ru' >
<head>
<meta charset='utf-8' />
<title></title>
<style>
body{
background-color:#F8F8FF
}
</style>
</head>
<body>
<div align='center'><H3> Подождите идет формирование выписки банка! </H3></div>
<div align='center'> <img src='" & Application.StartupPath & "\img\LoadGif.gif'" & " width='240' height='200' alt='LoadGif'>
</div>
</body>
</html>
"
'здесь показываю страницу ожидания
WebBrowser1.Document.OpenNew(False)
WebBrowser1.Document.Write(BodyHtml)
WebBrowser1.Refresh()
bgWorker.RunWorkerAsync()
ToolStripButton3.Enabled = False ' Запрещаем кнопку пока идет формирование выписки
End Sub |