<%
Function TyoboSeizouGenkaHokokusyo(EnshuCD, KaisyaCD, SakuseiKaisyaCD, BunsyoSyuruiCD, BunsyoNaiyoCD, AutoFlg, PrintFlg, Param1, Param2, Param3)

	Dim bExistSyuseiKinyu
	bExistSyuseiKinyu = 0
'	Query = "exec SPK伝票集計取得 '" & GB_SystemCD & "','" & EnshuCD & "', '" & KaisyaCD & "', '', -1, -1, 9"
'	Set Content = OpenQuery(Query)
'	If Not(Content.BOF Or Content.EOF) Then
'		bExistSyuseiKinyu = 1
'	End If

	Dim HiNikubun, TanaorosiKubun, Kaishibi, Syuryobi, tmp, tmp2
	Kaishibi = Param1
	Syuryobi = Param2
	tmp = Param3
	If tmp <> "" Then
		tmp2 = split(tmp, "-")
		HiNikubun = tmp2(0)
		TanaorosiKubun = tmp2(1)
	End If

	Dim KanjyoCDShiire, KanjyoCDKurikoshiSyohin
	Dim KanjyoCDKisyuSyohinTanaoroshidaka, KanjyoCDKimatsuSyohinTanaoroshidaka
	Dim KanjyoCDKurikoshiSoneki


	Query = "exec SPM勘定科目取得特別勘定 '" & GB_SystemCD & "','" & EnshuCD & "', ''"
	Set Content = OpenQuery(Query)
	Do While Not(Content.BOF OR Content.EOF)
		If Content.Fields("特別勘定区分") = "GL" Then
			KanjyoCDShiire = Content.Fields("勘定CD")
		ElseIf Content.Fields("特別勘定区分") = "GG" Then
			KanjyoCDKisyuSyohinTanaoroshidaka = Content.Fields("勘定CD")
		ElseIf Content.Fields("特別勘定区分") = "GH" Then
			KanjyoCDKimatsuSyohinTanaoroshidaka = Content.Fields("勘定CD")
		ElseIf Content.Fields("特別勘定区分") = "GJ" Then
			KanjyoCDKurikoshiSyohin = Content.Fields("勘定CD")
		ElseIf Content.Fields("特別勘定区分") = "GY" Then
			KanjyoCDKurikoshiSoneki = Content.Fields("勘定CD")
		End If
		
		Content.MoveNext
	Loop

	If PrintFlg = 0 Then
%>
<TABLE BORDER="0" CELLSPACING="5" CELLPADDING="0" STYLE="BORDER:0px solid #000000" WIDTH="660" HEIGHT="100%"><tr><td>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#FFFFFF" STYLE="BORDER:1px solid #000000" WIDTH="100%" HEIGHT="100%"><tr><td>
<%
	End If
%>
<TABLE BORDER="0" CELLSPACING="5" CELLPADDING="0" WIDTH="660" HEIGHT="100%">
	<TR>
		<TD ALIGN="CENTER" valign="top">
		<%
			If PrintFlg = 1 Then
				Response.Write(PrintHeader1(AutoFlg))
			End if
		%>
			<TABLE WIDTH="600" BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="100%">
				<TR>
					<TD HEIGHT="25" valign="top" WIDTH="600" align="center">
						<table border="0" width="600" cellspacing="0" cellpadding="0">
							<tr>
								<td width="170"> </td>
								<td class="bb2" align="center" nowrap><% = SetStringInsertSpace("製造原価報告書") %></td>
								<td width="170" class="tx1214" align="right"><% If HiNikubun = "1" Then Response.write("[売上原価を仕入高に集計]") End If %> </td>
							</tr>

						</table>
					</TD>
				</TR>
				<TR>
					<TD HEIGHT="20" VALIGN="BOTTOM" WIDTH="600">
						<TABLE WIDTH="600" HEIGHT="20" BORDER="1" CELLPADDING="0" CELLSPACING="0" BORDERCOLOR="#000000" BGCOLOR="#DDDDDD" CLASS="tx1416" STYLE="border-collapse: collapse">
							<TR ALIGN="CENTER">
								<TD WIDTH="240" HEIGHT="20">区分</TD>
								<TD WIDTH="241" HEIGHT="20">金額</TD>
								<TD HEIGHT="20">構成比</TD>
							</TR>
						</TABLE>
					</TD>
				</TR>

				<TR>
					<TD VALIGN="TOP">
						<% If PrintFlg <> 1 Then %>
						<DIV ID="Layer1" STYLE="position:relative; left:0px; top:-1px; width:620px; height:100%; z-index:1; border: 1px none #000000; overflow: auto;"> 
						<% End If %>
							<TABLE ID="SyoukaiList" WIDTH="600" BORDER="1" CELLSPACING="0" CELLPADDING="0" BORDERCOLOR="#000000" BGCOLOR="#FFFFFF" CLASS="tx1214" STYLE="border-collapse: collapse">
								<tr>
									<td VALIGN="TOP" width="100%">

										<%
											Dim Query
											Dim Content

											Dim DC,ww
											Dim TBLAC(2, 100)
											Dim TBLKIN(2, 100)
											Dim TBLNAME(2, 100)
											Dim TBLSUMCD(2, 100)
											Dim TBLSUMPM(2, 100)
											Dim TBLDCKubun(2, 100)
											Dim TBLKOSEI(2, 100)
											Dim TBLDSPLR(2, 100)
											Dim TBLDSPUL(2, 100)
											Dim TBLTKIN(2)

											Dim ii, jj, kk
											ii = 0
										'###########################################1.書式データ取得
											Query = "exec SPM報告書書式一覧 '" & GB_SystemCD & "','" & EnshuCD & "','G'"

											Set Content = OpenQuery(Query)

											Do While Not(Content.BOF Or Content.EOF)
												Dim SyukeiCD
												SyukeiCD = Content.Fields("集計CD")

'												If bExistSyuseiKinyu = 0 Or (bExistSyuseiKinyu = 1 And (HiNikubun <> "1" Or (SyukeiCD <> "G201" And SyukeiCD <> "G203" And SyukeiCD <> "G204" And SyukeiCD <> "G205"))) Then
													If IsNumeric(Content.Fields("ラインコントロール")) Then
														ii = ii + Int(Content.Fields("ラインコントロール"))
'													Else
'														ii = ii + 1
													End If
													ii = ii + 1
													ww = ii
													DC = 1

													TBLAC(DC, ww) = SyukeiCD
													TBLNAME(DC, ww) = Content.Fields("集計名称")
													TBLSUMCD(DC, ww) = Content.Fields("集計先")
													TBLSUMPM(DC, ww) = Content.Fields("加減区分")
													TBLDCKubun(DC, ww) = Content.Fields("貸借")
													TBLKOSEI(DC, ww) = Content.Fields("構成表示")
													TBLDSPLR(DC, ww) = Content.Fields("右方表示")
													TBLDSPUL(DC, ww) = Content.Fields("アンダーライン")
'													If bExistSyuseiKinyu = 1 And HiNikubun = "1" Then
'														If SyukeiCD = "P202" Then
'															TBLNAME(DC, ww) = Replace(TBLNAME(DC, ww), "2.", "")
'															TBLSUMCD(DC, ww) = "P295"
'															TBLSUMPM(DC, ww) = "-"
'														End If
'														If SyukeiCD = "P200" Then
'															TBLDSPUL(DC, ww) = ""
'														End If
'													End If

													If InStr(TBLNAME(DC, ww), "小計") > 0 Then
														TBLNAME(DC, ww) = Replace(TBLNAME(DC, ww), "  ", " ")
													End If
'												End If
												Content.MoveNext
											Loop

											Dim HokokusyoLines,yy

											HokokusyoLines = ii
											yy = jj

											Dim RowCount, RowBreakNum

											ii = 0
											jj = 0

											RowCount = 0

										'###########################################2.金額データ取得
											Query = "exec SPK自動転記帳簿_財務諸表 '" & GB_SystemCD & "','" & EnshuCD & "', '" & KaisyaCD & "','" & Kaishibi & "','" & Syuryobi & "','P', 1, 9"

											Set Content = OpenQuery(Query)
											Dim RecordCount
											RecordCount = 0
											Do While Not(Content.BOF Or Content.EOF)
												If "" & Content.Fields("業種CD") = "G" Then
													RecordCount = RecordCount + 1
												End If
												Content.MoveNext
											Loop
											ShowCount = RecordCount
											MaxCount = RecordCount + 5
											RowBreakNum = MaxCount

											ReDim WK_Zandaka_KanjyoCD(MaxCount)
											ReDim WK_Zandaka_KanjyoName(MaxCount)
											ReDim WK_Zandaka_KariKingaku(MaxCount)
											ReDim WK_Zandaka_KashiKingaku(MaxCount)
											ReDim WK_Zandaka_KanjyoKubun(MaxCount)
											ReDim WK_Zandaka_TaisyakuKubun(MaxCount)
											ReDim WK_Zandaka_SyukeiCD(MaxCount)


											Set Content = OpenQuery(Query)
											'//////////////////////////////// ワーク「残高F」を作成
											Do While Not(Content.BOF Or Content.EOF)
												If "" & Content.Fields("業種CD") = "G" Then
													ii = ii + 1
													WK_Zandaka_KanjyoCD(ii) = Content.Fields("勘定CD")
													WK_Zandaka_KanjyoName(ii) = Content.Fields("勘定名称")
													WK_Zandaka_KanjyoKubun(ii) = Content.Fields("勘定区分")
													WK_Zandaka_TaisyakuKubun(ii) = Content.Fields("貸借区分")
													WK_Zandaka_SyukeiCD(ii) = Content.Fields("製造原価報告書集計CD")


													WK_Zandaka_KariKingaku(ii) = Content.Fields("借方金額")
													WK_Zandaka_KashiKingaku(ii) = Content.Fields("貸方金額")
'																Select Case KaisyaKbn
'																	Case "0"
'																		WK_Zandaka_KariKingaku(ii) = Content.Fields("本社借方")
'																		WK_Zandaka_KashiKingaku(ii) = Content.Fields("本社貸方")
'																	Case "1"
'																		WK_Zandaka_KariKingaku(ii) = Content.Fields("支店借方")
'																		WK_Zandaka_KashiKingaku(ii) = Content.Fields("支店貸方")
'																	Case Else
'																		WK_Zandaka_KariKingaku(ii) = Content.Fields("本社借方") + Content.Fields("支店借方")
'																		WK_Zandaka_KashiKingaku(ii) = Content.Fields("本社貸方") + Content.Fields("支店貸方")
'																End Select

													If Content.Fields("勘定CD") = KanjyoCDKurikoshiSoneki Then
														WK_Zandaka_SyukeiCD(ii) = "P910"
													End If
												End If
												Content.MoveNext
											Loop


								'棚卸の調整ここから
								If (bExistSyuseiKinyu = 0 And TanaorosiKubun = "1") Or (bExistSyuseiKinyu = 1 And HiNikubun <> "1") Then	

									'在庫数をチェックする。
									Dim KimatsuSyohinTanaoroshidaka, KisyuSyohinTanaoroshidaka
									KisyuSyohinTanaoroshidaka = KisyuTanaoroshiKingaku(Syuryobi)
									KimatsuSyohinTanaoroshidaka = KimatsuTanaoroshiKingaku(Syuryobi)


									Dim KurikosiFLG, InsertNo
									Dim i ,j

'													For jj = 1 To RecordCount
'														Response.Write(jj & "-" & WK_Zandaka_KanjyoCD(jj) & "<br>")
'													Next

									'繰越商品を削除ここから
									For jj = 1 To RecordCount
										If WK_Zandaka_KanjyoCD(jj) = KanjyoCDKurikoshiSyohin Then
											For ii = jj To RecordCount - 1
												WK_Zandaka_KanjyoCD(ii) = WK_Zandaka_KanjyoCD(ii + 1)
												WK_Zandaka_KanjyoName(ii) = WK_Zandaka_KanjyoName(ii + 1)
												WK_Zandaka_KariKingaku(ii) = WK_Zandaka_KariKingaku(ii + 1)
												WK_Zandaka_KashiKingaku(ii) = WK_Zandaka_KashiKingaku(ii + 1)
												WK_Zandaka_TaisyakuKubun(ii) = WK_Zandaka_TaisyakuKubun(ii + 1)
												WK_Zandaka_SyukeiCD(ii) = WK_Zandaka_SyukeiCD(ii + 1)
											Next
											WK_Zandaka_KanjyoCD(ii) = ""
											WK_Zandaka_KanjyoName(ii) = ""
											WK_Zandaka_KariKingaku(ii) = null
											WK_Zandaka_KashiKingaku(ii) = null
											WK_Zandaka_TaisyakuKubun(ii) = ""
											WK_Zandaka_SyukeiCD(ii) = ""
											ShowCount = ShowCount - 1
											Exit For
										End If
									Next
									'繰越商品を削除ここまで


									'期首商品棚卸高ここから
										tmp = ReplaceKanjyo(KanjyoCDKisyuSyohinTanaoroshidaka, KisyuSyohinTanaoroshidaka, 0)

										Query = "exec SPK伝票集計取得 '" & GB_SystemCD & "','" & EnshuCD & "', '" & KaisyaCD & "', '" & KanjyoCDKisyuSyohinTanaoroshidaka & "', 0, 1, 9"
										Set Content = OpenQuery(Query)
										If Not(Content.BOF Or Content.EOF) Then
											tmp = ReplaceKanjyo(KanjyoCDKisyuSyohinTanaoroshidaka, Content.Fields("借方金額"), Content.Fields("貸方金額"))
										End If
									'期首商品棚卸高ここまで



									'期末商品棚卸高ここから
										tmp = ReplaceKanjyo(KanjyoCDKimatsuSyohinTanaoroshidaka, 0, KimatsuSyohinTanaoroshidaka)

										Query = "exec SPK伝票集計取得 '" & GB_SystemCD & "','" & EnshuCD & "', '" & KaisyaCD & "', '" & KanjyoCDKimatsuSyohinTanaoroshidaka & "', 0, 1, 9"
										Set Content = OpenQuery(Query)
										If Not(Content.BOF Or Content.EOF) Then
											tmp = ReplaceKanjyo(KanjyoCDKimatsuSyohinTanaoroshidaka, Content.Fields("借方金額"), Content.Fields("貸方金額"))
										End If
									'期末商品棚卸高ここまで

										If bExistSyuseiKinyu = 1 Then
											tmp = ReplaceKanjyo(KanjyoCDShiire, KityuShiireKingaku(Syuryobi), 0)
										End If

'													チェック用
'													For jj = 1 To RecordCount + 2
'														Response.Write(WK_Zandaka_KanjyoCD(jj) & "-")
'														Response.Write(WK_Zandaka_KanjyoName(jj) & "-")
'														Response.Write(WK_Zandaka_KariKingaku(jj) & "-")
'														Response.Write(WK_Zandaka_KashiKingaku(jj) & "-")
'														Response.Write(WK_Zandaka_TaisyakuKubun(jj) & "-")
'														Response.Write(WK_Zandaka_SyukeiCD(jj) & "-")
'														Response.Write("<br>")
'													Next

								End If


											ReDim DSP_KarikataKingakuTotal(RecordCount),DSP_KashikataKingakuTotal(RecordCount)
											Dim DSP_SisanFusaiKingakuTotal,DSP_SisanKingakuTotal

											'/////////////////////////////////ワーク「残高F」から書式の科目毎に振り分ける
											ii = 0
											Dim WK_KIN,WK_AC,WK_DC,WK_PM,W_NOTF,Sww,Sxx_SET,Sxx
											For ii = 1 To MaxCount

												DC = 1
												If WK_Zandaka_TaisyakuKubun(ii) = "D" Then
													WK_KIN = WK_Zandaka_KariKingaku(ii) - WK_Zandaka_KashiKingaku(ii)
												Else
													WK_KIN = WK_Zandaka_KashiKingaku(ii) - WK_Zandaka_KariKingaku(ii)
												End If


												WK_PM = "+"
												W_NOTF = True

												If WK_KIN <> 0 Then
													WK_AC = WK_Zandaka_SyukeiCD(ii)		'集計先
													WK_DC = WK_Zandaka_TaisyakuKubun(ii)	'貸借区分

													If TBLTKIN(DC) <> 0 Then
														TBLTKIN(DC) = ConvMoneyToInt(TBLTKIN(DC)) + ConvMoneyToInt(WK_KIN)
													Else
														TBLTKIN(DC) = ConvMoneyToInt(WK_KIN)
													End If


													For jj = 1 To HokokusyoLines

														If TBLAC(DC, jj) = WK_AC And WK_AC <> "" Then	'空白行(集計CD="")と諸表集計CD=""が合致してしまうので諸表集計CD=""は除外

															If (WK_DC <> TBLDCKubun(DC, jj)) Then
																WK_KIN = WK_KIN * -1
															End If

															If (WK_PM <> "+") Then
																WK_KIN = WK_KIN * -1
															End If

															TBLKIN(DC, jj) = TBLKIN(DC, jj) + WK_KIN

															WK_AC = TBLSUMCD(DC, jj)
															WK_PM = TBLSUMPM(DC, jj)
															W_NOTF = False
															ww = jj

															Exit For

														End If

													Next

												End If
											Next

											For jj = 1 To HokokusyoLines
												If TBLKIN(DC, jj) <> "" Then
													For kk = jj + 1 To HokokusyoLines
														If TBLAC(DC, kk) = TBLSUMCD(DC, jj) Then
															If TBLSUMPM(DC, jj) <> "-" Then
																TBLKIN(DC, kk) = TBLKIN(DC, kk) + TBLKIN(DC, jj)
															Else
																TBLKIN(DC, kk) = TBLKIN(DC, kk) - TBLKIN(DC, jj)
															End If

														End If
													Next
												End If
											Next

										'###########################################3.当期利益の算出


										'###########################################4.画面出力
											ii = 0
											'/////////////////////// 資産の列(左)
											Response.Write("<table width=""100%"" border=""0"" CELLSPACING=""0"" CELLPADDING=""0"" CLASS=""tx1214"">")
											For ii = 1 To HokokusyoLines

												Response.Write("<tr>" & vbCrLf)

												'名称
												Response.Write("<td nowrap width=""240""")
												If TBLDSPUL(1, ii) = "1" Then
													Response.Write(" style=""border-bottom: solid 1 #000000;""")
												Else
													Response.Write(" style=""border-bottom: solid 1 #FFFFFF;""")
												End If
												Response.Write(" style=""border-right: solid 1 #000000;"">" & TBLNAME(1,ii))
												Response.Write("<br></td>" & vbCrLf)

												'金額
												If TBLDSPLR(1,ii) = "R" Then
													Response.Write("<td width=""120"" align=""right""")
													If TBLDSPUL(1, ii) = "1" Then
														Response.Write(" style=""border-bottom: solid 1 #000000;""")
													End If
													Response.Write(" style=""border-right: solid 1 #000000;"">")
													Response.Write("<br></td>" & vbCrLf)

													Response.Write("<td width=""120"" align=""right""")
													If TBLDSPUL(1, ii) = "1" Then
														Response.Write(" style=""border-bottom: solid 1 #000000;""")
													End If
													Response.Write(" style=""border-right: solid 1 #000000;"">")
'													If TBLAC(1, ii) <> "" Then
														Response.Write(ConvIntToMoney(TBLKIN(1,ii), false, true))
'													End If
													Response.Write("<br></td>" & vbCrLf)
												Else
													Response.Write("<td width=""120"" align=""right""")
													If TBLDSPUL(1, ii) = "1" Then
														Response.Write(" style=""border-bottom: solid 1 #000000;""")
													End If
													Response.Write(" style=""border-right: solid 1 #000000;"">")
'													If TBLAC(1, ii) <> "" Then
														Response.Write(ConvIntToMoney(TBLKIN(1,ii), false, true))
'													End If
													Response.Write("<br></td>" & vbCrLf)

													Response.Write("<td width=""120"" align=""right""")
													If TBLDSPUL(1, ii) = "1" Then
														Response.Write(" style=""border-bottom: solid 1 #000000;""")
													End If
													Response.Write(" style=""border-right: solid 1 #000000;"">")
													Response.Write("<br></td>" & vbCrLf)
												End If

												'構成比
												Response.Write("<td align=""right""")
												If TBLDSPUL(1, ii) = "1" Then
													Response.Write(" style=""border-bottom: solid 1 #000000;""")
												End If
												Response.Write("><img src=""/" & HomeAlias & "/images/spacer.gif"" width=""1"" height=""1"">")

												If TBLKOSEI(1,ii) = "1" and TBLKIN(1,ii) <> 0 and TBLKIN(1,ii) <> "" and TBLKIN(1,1) <> "" Then
													Response.Write(" " & Int(TBLKIN(1,ii) * 1000 / TBLKIN(1, 1)) / 10 & "%")
												End If

												Response.Write("<br></td>" & vbCrLf)

												Response.Write("</tr>" & vbCrLf)
											Next

											Response.Write("</table>" & vbCrLf)
											'/////////////////////// 負債及び資本の列(右)

										%>
									</td>
								</tr>
							</TABLE>
<%
	Dim MiteiFlg
	MiteiFlg = 0
									For jj = 1 To RecordCount
										If WK_Zandaka_KanjyoCD(jj) <> "" And WK_Zandaka_SyukeiCD(jj) = "" Then
											MiteiFlg = 1
											Exit For
										End If
									Next
%>
<% If MiteiFlg > 0 Then %>
							<BR>集計先が定まっていない残高
							<TABLE ID="SyoukaiListMitei" WIDTH="600" BORDER="1" CELLSPACING="0" CELLPADDING="0" BORDERCOLOR="#000000" BGCOLOR="#FFFFFF" CLASS="tx1214" STYLE="border-collapse: collapse">
								<tr>
									<td align="center">勘定CD</td>
									<td align="center">勘 定 名 称</td>
									<td align="center">貸借</td>
									<td align="center">借 方 勘 定</td>
									<td align="center">貸 方 勘 定</td>
								</tr>
<%
									'集計先未定
									For jj = 1 To RecordCount
										If WK_Zandaka_KanjyoCD(jj) <> "" And WK_Zandaka_SyukeiCD(jj) = "" Then
											Response.Write("<tr>")
											Response.Write("<td align=""center"">")
											Response.Write(WK_Zandaka_KanjyoCD(jj))
											Response.Write("</td>")
											Response.Write("<td>&nbsp;")
											Response.Write(WK_Zandaka_KanjyoName(jj))
											Response.Write("</td>")
											Response.Write("<td align=""center"">")
											If WK_Zandaka_TaisyakuKubun(jj) = "D" Then
												Response.Write("借")
											Else
												Response.Write("貸")
											End If
											Response.Write("</td>")
											Response.Write("<td align=""right"">&nbsp;")
											Response.Write(WK_Zandaka_KariKingaku(jj))
											Response.Write("&nbsp;</td>")
											Response.Write("<td align=""right"">&nbsp;")
											Response.Write(WK_Zandaka_KashiKingaku(jj))
											Response.Write("&nbsp;</td>")
											Response.Write("</tr>")
										End If
									Next
%>
							</TABLE>
<% End If %>
						<% If PrintFlg <> 1 Then %>
						</DIV>
						<% End If  %>
					</TD>
				</TR>
			</TABLE>
		</TD>
	</TR>
</TABLE>
<%
	If PrintFlg = 0 Then
%>
</td></tr></table>
</td></tr></table>
<%
	End if

End Function



Function ReplaceKanjyo(F_KanjyoCD, F_KarikataKingaku, F_KashikataKingaku)
	If IsNull(F_KarikataKingaku) Then F_KarikataKingaku = 0 End If
	If IsNull(F_KashikataKingaku) Then F_KashikataKingaku = 0 End If
	Dim InsertNo, KurikosiFLG
	Dim ii, jj
	Dim Query, Content
	InsertNo = -1
	KurikosiFLG = 0
	If F_KarikataKingaku <> 0 OR F_KashikataKingaku <> 0  Then
		For jj = 1 To MaxCount
			If WK_Zandaka_KanjyoCD(jj) = "" Then
				Exit For
			End If

			If WK_Zandaka_KanjyoCD(jj) > F_KanjyoCD Then

				If KurikosiFLG = 0 Then
					For ii = MaxCount - 1 To jj Step -1
						WK_Zandaka_KanjyoCD(ii + 1) = WK_Zandaka_KanjyoCD(ii)
						WK_Zandaka_KanjyoName(ii + 1) = WK_Zandaka_KanjyoName(ii)
						WK_Zandaka_KariKingaku(ii + 1) = WK_Zandaka_KariKingaku(ii)
						WK_Zandaka_KashiKingaku(ii + 1) = WK_Zandaka_KashiKingaku(ii)
						WK_Zandaka_TaisyakuKubun(ii + 1) = WK_Zandaka_TaisyakuKubun(ii)
						WK_Zandaka_SyukeiCD(ii + 1) = WK_Zandaka_SyukeiCD(ii)
					Next
					InsertNo = jj
					KurikosiFLG = 1
					ShowCount = ShowCount + 1
					Exit For
				End If
			ElseIf WK_Zandaka_KanjyoCD(jj) = F_KanjyoCD Then
			'すでに残高に「期末商品棚卸高」がある場合
				KurikosiFLG = 1
				InsertNo = jj
			End If
		Next
		If KurikosiFLG = 0 Then
			InsertNo = jj
			ShowCount = ShowCount + 1
		End If
	End If

	If InsertNo <> -1 Then
		Query = "exec SPM勘定科目取得 '" & GB_SystemCD & "','" & EnshuCD & "', '" & F_KanjyoCD & "'"
		Set Content = OpenQuery(Query)
		If Not(Content.BOF Or Content.EOF) Then
			WK_Zandaka_TaisyakuKubun(InsertNo) = Content.Fields("貸借区分")
			WK_Zandaka_KanjyoName(InsertNo) = Content.Fields("勘定名称")
			WK_Zandaka_SyukeiCD(InsertNo) = Content.Fields("製造原価報告書集計CD")
		End If

		WK_Zandaka_KanjyoCD(InsertNo) = F_KanjyoCD

		If WK_Zandaka_TaisyakuKubun(InsertNo) = "C" Then
			WK_Zandaka_KariKingaku(InsertNo) = 0
			WK_Zandaka_KashiKingaku(InsertNo) = F_KashikataKingaku - F_KarikataKingaku
		Else
			WK_Zandaka_KariKingaku(InsertNo) = F_KarikataKingaku - F_KashikataKingaku
			WK_Zandaka_KashiKingaku(InsertNo) = 0
		End If
	End If

End Function
%>