<%
Function UnsoSeikyuSyorui(EnshuCD, KaisyaCD, SakuseiKaisyaCD, BunsyoSyuruiCD, BunsyoNaiyoCD, AutoFlg, PrintFlg)

	'マスタの標準消費税率を取得
	Dim StdTaxRate
	Dim StdTaxRateUnso
	StdTaxRate = GB_Shohizei
	StdTaxRateUnso = GB_Shohizei
	If GB_ShohizeiMode = 1 Then
		Query = " SELECT * FROM TDA消費税率M WHERE システムCD = '" & GB_SystemCD & "' AND 演習CD = '" & EnshuCD & "' AND (標準 = '1' OR 運送費標準 = '1') "
		Set Content = OpenQuery(Query)
		Do While Not(Content.BOF Or Content.EOF)
			If "" & Content.Fields("標準") = "1" Then
				StdTaxRate = Content.Fields("消費税率")
			End If
			If "" & Content.Fields("運送費標準") = "1" Then
				StdTaxRateUnso = Content.Fields("消費税率")
			End If
			Content.MoveNext
		Loop
	End If

	Dim TmpCnt

	Dim Query, Query2
	Dim Content

	Dim Action   
	Dim TorihikisakiCD

	Dim Syoribi, GakuseiBango
	Dim ShiharaiHoho , HasshinFlg, Tekiyo
	Dim SakujyoFlg
	Dim GokeiKingaku, SyohizeiKingaku, ZeikomiKingaku
	Dim ShiireUriageBunsyoNaiyoCD, tmps
	Dim DbTorihikisakiCD
	Dim DbSakuseiKaishaCD
	Dim BunsyoKubun
	Dim MeisaiUnsobi(5)
	Dim MeisaiUnsosakiCD(5)
	Dim MeisaiUnsohi(5)
	Dim MeisaiUnsosakiMeisyo(5)

	For ii = 1 To 5
		MeisaiUnsobi(ii) = ""
		MeisaiUnsosakiCD(ii) = ""
		MeisaiUnsohi(ii) = ""
		MeisaiUnsosakiMeisyo(ii) = ""
	Next

	Dim RouteType
	RouteType = Request("RouteType")

	Dim SenpoFlg
	SenpoFlg = 0
	If SakuseiKaisyaCD <> KaisyaCD Then
		SenpoFlg = 1
	End IF

	TorihikisakiCD = Request("TorihikisakiCD")

	If SenpoFlg = 1 Then
		If GB_JisyaFlag <> "" Then	'運用管理・演習管理(自社フラグ無し)では開封フラグを立てない(061213小野)
			Query = "exec SPC運送費請求書開封 '" & GB_SystemCD & "','" & EnshuCD & "', '" & KaisyaCD & "', '" & SakuseiKaisyaCD & "', '" & BunsyoSyuruiCD & "', '" & BunsyoNaiyoCD & "'"
			Set Content = OpenQuery(Query)
		End If
		Query = "exec SPC運送費請求書取得 '" & GB_SystemCD & "','" & EnshuCD & "', '" & KaisyaCD & "', '" & SakuseiKaisyaCD & "', '" & BunsyoSyuruiCD & "', '" & BunsyoNaiyoCD & "'"
	Else
		Query = "exec SPC運送費請求書取得 '" & GB_SystemCD & "','" & EnshuCD & "', '" & KaisyaCD & "', '" & SakuseiKaisyaCD & "', '" & BunsyoSyuruiCD & "', '" & BunsyoNaiyoCD & "'"
	End If
'Response.Write(Query)
'Exit Function

	Set Content = OpenQuery(Query)
	If Not(Content.BOF Or Content.EOF) Then
		Syoribi = SetTimeYYYYMMDD(Content.Fields("処理日"))
		DbTorihikisakiCD = Content.Fields("取引先CD")
		DbSakuseiKaishaCD = Content.Fields("作成会社CD")
		ShiharaiHoho = Content.Fields("支払方法")
		Tekiyo = Content.Fields("摘要")
		HasshinFlg = Content.Fields("発行フラグ")
		SakujyoFlg = Content.Fields("削除フラグ")
		GakuseiBango = Content.Fields("学生番号")

		BunsyoKubun = Content.Fields("文書区分")
		If BunsyoKubun = "CA" Then
			ShiireUriageBunsyoNaiyoCD = Content.Fields("納品請求書番号群")
		Else
			ii = 0
			Do While Not(Content.BOF Or Content.EOF)
				ii = ii + 1
					MeisaiUnsobi(ii) = SetTimeYYYYMMDD(Content.Fields("運送日"))
					MeisaiUnsosakiCD(ii) = Content.Fields("運送先CD")
					MeisaiUnsohi(ii) = Content.Fields("運送費")
					MeisaiUnsosakiMeisyo(ii) = ConvKaisyaMeisyoDx(EnshuCD, MeisaiUnsosakiCD(ii))
				Content.MoveNext
			Loop

		End If


	End If

	For ii = 1 To 5
		If MeisaiUnsosakiMeisyo(ii) = "" Then
			MeisaiUnsosakiMeisyo(ii) = "以下余白"
			Exit For
		End If
	Next

	Dim SyoruiMei, Title
	SyoruiMei = "運送費請求書"
	Title = SyoruiMei

	'請求元情報取得(100917小野)※請求先を表示してしまっていたので修正(150511小野)
	Dim Adr1
	Dim Adr2
	Query = "exec SPM会社取得 '" & GB_SystemCD & "','" & EnshuCD & "','" & DbSakuseiKaishaCD & "'"
	Set Content = OpenQuery(Query)
	If Not(Content.BOF Or Content.EOF) Then
		Adr1 = Content.Fields("住所1")
		Adr2 = Content.Fields("住所2")
	End If

%>


<%	If PrintFlg = 1 Then  %>
	<table width="640" height="100%" border="0" cellpadding="0" cellspacing="0">
		<tr> 
			<td align="center" valign="top">
<%	Response.Write(PrintHeader(AutoFlg, "")) %>
<%	Else %>
	<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="5">
		<tr>
		<td align="center" valign="middle">	 
<%	End if %>
			<table width="550" height="430" border="0" cellpadding="0" cellspacing="5">
				<tr>
					<td align="center">
						<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border:solid 1px #111111">
							<tr>
								<td height="190" align="center" valign="bottom">
									<table width="550" height="180" border="0" cellpadding="0" cellspacing="0">
										<tr>
											<td height="60" align="center" valign="top">
												<table width="530" height="50" border="0" cellpadding="0" cellspacing="0">
													<tr>
														<td>&nbsp;</td>
														<td valign="top">
															<table width="130" border="0" cellpadding="0" cellspacing="0" style="border-bottom: 1px solid #000000" class="tx2022">
																<tr>
																	<td align="center" nowrap><%
																		Dim ii
																		If Len(SyoruiMei) < 8 Then
																			Response.Write(SetStringInsertSpace(SyoruiMei))
																		Else
																			Response.Write(SyoruiMei)
																		End If
																	%></td>
																</tr>
															</table>
														</td>
														<td width="165">
															<table height="50" border="0" cellpadding="0" cellspacing="0">
																<tr class="tx1416">
																	<td width="60" height="25">書類番号</td>
																	<td width="105" height="25">:<% = BunsyoNaiyoCD %></td>
																</tr>
																<tr class="tx1416">
																	<td height="25">処 理 日</td>
																	<td height="25">:<% = Syoribi %></td>
																</tr>
															</table>
														</td>
														<td width="150" align="right" valign="bottom">
															<table width="150" height="50" border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" STYLE="border-collapse: collapse">
																<tr class="tx1214" >
																	<td width="50" height="15" align="center">&nbsp;</td>
																	<td width="50" height="15" align="center">&nbsp;</td>
																	<td width="50" height="15" align="center">係 印</td>
																</tr>
																<tr class="tx1416">
																	<td width="50" height="35" align="center">&nbsp;</td>
																	<td width="50" height="35" align="center">&nbsp;</td>
																	<td width="50" height="35" align="center"><% = ConvShimeiRyakuMeisyo(GakuseiBango) %></td>
																</tr>
															</table>
														</td>
														<td>&nbsp;</td>
													</tr>
												</table>
											</td>
										</tr>
										<tr>
											<td align="center" valign="middle">
												<table border="0" cellpadding="0" cellspacing="0">
													<tr class="tx1618">
														<td width="70" height="25">取 引 先</td>
														<td width="200">:<% = ConvKaisyaMeisyoDx(EnshuCD, DbTorihikisakiCD) %></td>
														<td width="200"><% = ConvKaisyaMeisyoDx(EnshuCD, DbSakuseiKaishaCD) %></td><!--運送会社情報-->
													</tr>
													<tr class="tx1618">
														<td height="25">支払方法</td>
														<td>:<% = ShiharaiHoho %></td>
														<td><% = Adr1 %></td><!--運送会社情報-->
													</tr>
													<tr class="tx1618">
														<td height="25">摘  要</td>
														<td>:<% = Tekiyo %></td>
														<td><% = Adr2 %></td><!--運送会社情報-->
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td height="240" align="center" valign="top">
									<table width="550" height="230" border="0" cellpadding="4" cellspacing="0">
										<tr>
											<td width="100%" align="RIGHT">
												<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="530" bordercolor="#000000">
													<tr>
														<td height="150" valign="TOP">
															<TABLE WIDTH="530" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="100%">
																<TR>
																	<TD HEIGHT="20" VALIGN="BOTTOM" WIDTH="530">
																		<TABLE WIDTH="500" BORDER="1" CELLPADDING="0" CELLSPACING="0" BORDERCOLOR="#000000" BGCOLOR="#FFFFCC" CLASS="tx1618" STYLE="border-collapse: collapse">
																			<TR ALIGN="CENTER" bgcolor="#DDDDDD">
																				<!--<TD WIDTH="50">番号</TD>-->
																				<TD WIDTH="120">処理日</TD>
																				<TD HEIGHT="23">運送先</TD>
																				<TD WIDTH="120">金額</TD>
																			</TR>
																			<%
																			If BunsyoKubun <> "CA" Then
																		 	GokeiKingaku = 0
																			For ii = 1 To 5 %>
																			<TR ALIGN="CENTER" bgcolor="#FFFFFF">
																				<TD WIDTH="120" class="tx1618"><% = MeisaiUnsobi(ii) %></TD>
																				<TD HEIGHT="23"><% = MeisaiUnsosakiMeisyo(ii) %></TD>
																				<TD WIDTH="120" align="right" class="tx1618"><% = ConvIntToMoney(MeisaiUnsohi(ii), false, false) %></TD>
																			</TR>
																			<%
																		 	If MeisaiUnsohi(ii) <> "" Then
																			 	GokeiKingaku =	GokeiKingaku + MeisaiUnsohi(ii)
																		 	End If
																			Next
																			'SyohizeiKingaku = Int(GokeiKingaku * GB_Shohizei / 100)
																			SyohizeiKingaku = Int(GokeiKingaku * StdTaxRateUnso / 100)
																			ZeikomiKingaku = GokeiKingaku + SyohizeiKingaku
																			End If %>

																		</TABLE>

																	</TD>
																</TR>
																<% If BunsyoKubun = "CA" Then %>
																<TR>
																	<TD VALIGN="TOP" >
		<% If PrintFlg = 0 Then %>
																		<DIV ID="Layer1" STYLE="position:relative; left:0px; top:0px; width:520px; height:100%; z-index:1; border: 1px none #000000; overflow: auto;">
		<% End If %>
																			<TABLE ID="SyoukaiList" WIDTH="500" BORDER="1" CELLSPACING="0" CELLPADDING="0" class="tx1618" BGCOLOR="#FFFFFF" STYLE="border-collapse: collapse" BORDERCOLOR="#000000">
																			<%

																				If SenpoFlg = 1 Then
																					Query2 = "exec SPC運送費請求一覧 '" & GB_SystemCD & "','" & EnshuCD & "', '" & SakuseiKaisyaCD & "', '" & DbTorihikisakiCD	& "','" & GB_KaikeiSyuryobi & "'"
																				Else
																					Query2 = "exec SPC運送費請求一覧 '" & GB_SystemCD & "','" & EnshuCD & "', '" & KaisyaCD & "', '" & DbTorihikisakiCD & "','" & GB_KaikeiSyuryobi & "'"
																				End If
'Response.Write(Query2)
'Exit Function

																				TorihikisakiCD = DbTorihikisakiCD

																				Dim SyoriYMD

																				tmps = split(ShiireUriageBunsyoNaiyoCD, ",")


																				GokeiKingaku = 0
																				Dim kk, bExist
																				ii = 0

																				Set Content = OpenQuery(Query2)

																					Do While Not(Content.BOF Or Content.EOF)
																				 	bExist = 0
																				 	For kk = 0 To UBound(tmps)
																				 		Dim tmpss
																				 		tmpss = split(tmps(kk), ":")

																				 		If UBound(tmpss) = 1 Then
																					 		If Content.Fields("会社CD") = tmpss(0) And Content.Fields("文書種類CD") = "KN" And Int(Content.Fields("文書内容CD")) = Int(tmpss(1)) Then
																				 				bExist = 1
																				 			End if
																				 		ElseIf UBound(tmpss) = 2 Then
																					 		If Content.Fields("会社CD") = tmpss(0) And Content.Fields("文書種類CD") = tmpss(1) And Content.Fields("文書内容CD") = tmpss(2) Then
																				 				bExist = 1
																				 			End if
																				 		End If
																				 	Next
																				 	If bExist = 1 Then
																				 		GokeiKingaku = GokeiKingaku + Content.Fields("運送費")
																							Response.Write("<TR ALIGN=""CENTER"">" & vbCrLf)
																			'			Response.Write("<TD WIDTH=""50"" HEIGHT=""20"">" & Content.Fields("文書内容CD") & "</TD>" & vbCrLf)
																						Response.Write("<TD WIDTH=""120"" HEIGHT=""23"" ALIGN=""center"" class=""tx1618"">" & SetTimeYYYYMMDD(Content.Fields("処理日")) & "</TD>" & vbCrLf)
																						Response.Write("<TD HEIGHT=""23"">" & ConvKaisyaMeisyoDx(EnshuCD, Content.Fields("取引先CD")) & "</TD>" & vbCrLf)
																						Response.Write("<TD WIDTH=""120"" HEIGHT=""23"" ALIGN=""right"" class=""tx1618"">" & ConvIntToMoney(Content.Fields("運送費"), false, false) & "</TD>" & vbCrLf)
																						ii = ii + 1
																						Response.Write("</TR>")
																					End If
																				 	Content.MoveNext
																					Loop
																					Dim jj
																					For jj = ii To 6
																				 	Response.Write("<TR ALIGN=""CENTER"">" & vbCrLf)
																					Response.Write("<TD WIDTH=""100""></TD>" & vbCrLf)
																					Response.Write("<TD HEIGHT=""23"">")
																					If jj = ii Then
																						Response.Write("以下余白")
																					End If
																					Response.Write("</TD>" & vbCrLf)
																					Response.Write("<TD WIDTH=""100"" HEIGHT=""23"" ALIGN=""LEFT""></TD>" & vbCrLf)
																					Response.Write("</TR>")
																					Next

																					'SyohizeiKingaku = Int(GokeiKingaku * GB_Shohizei / 100)
																					SyohizeiKingaku = Int(GokeiKingaku * StdTaxRateUnso / 100)
																					ZeikomiKingaku = GokeiKingaku + SyohizeiKingaku
																				%>
																			</TABLE>
		<% If PrintFlg = 0 Then %>
																		</DIV>
		<% End If %>
																	</TD>
																</TR>
																<% End If %>
															</TABLE>

														</td>
													</tr>
													<tr>
														<td>
															<table width="500" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#000000" bgcolor="#DDDDDD"  class="tx1618">
																<tr>
																	<td align="center" width="250" rowspan="4">
																	</td>
																	<td align="center">合計金額</td>
																	<td align="right" bgcolor="#FFFFFF" width="120" height="25" class="tx1618"><% = SetMoney(GokeiKingaku, false, false) %></td>
																</tr>
																<tr>
																	<td align="center">消費税額</td>
																	<td align="right" bgcolor="#FFFFFF" width="120" height="25" class="tx1618"><% = SetMoney(SyohizeiKingaku, false, false) %></td>
																</tr>
																<tr>
																	<td align="center">税込金額</td>
																	<td align="right" bgcolor="#FFFFFF" width="120" height="25" class="tx1618"><% = SetMoney(ZeikomiKingaku, false, false) %></td>
																</tr>
															</table>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table>

								</td>
							</tr>
						</table>
					</td>
		<% If SenpoFlg = 0 And PrintFlg = 0 Then  %>
					<td valign="top" class="tx1618"><br><br>
						<table width="100%" height="200" border="0" cellpadding="3" cellspacing="0"	bgcolor="#eeeeff" style="border:solid 1px #111111">
							<tr>
								<td valign="top">
									<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" >
										<tr>
											<td valign="top">
												<table BORDER="0" CELLSPACING="0" CELLPADDING="2" class="tx1618" width="160">
													<tr>
														<td>この書類に関する情報</td>
													</tr>
													<tr>
														<td> </td>
													</tr>
													<tr>
														<td>発信: <% = ConvFlagMeisyo(HasshinFlg, 5) %></td>
													</tr>
													<tr>
														<td height="15"></td>
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</td>
		<%	End If %>
				</tr>
			</table>
		<%
			If PrintFlg = 1 Then
				Response.Write(PrintFooter())
			End if
		%>
		</td>
	</tr>
</table>
<%
End Function
%>