示例#1
0
function out_html($gc) {

	$gc->company_sh = $_GET["company_sh"];
	$gc->todoufuken_no = $_GET["todoufuken_no"];
	$gc->company_no = $_GET["company_no"];
	$gc->company_kbn = $_GET["company_kbn"];
	$gc->relocation_flg = $_GET["relocation_flg"];

	$arr_todoufuken = fsel_get_arr_todoufuken($gc);

	$arr_company_kbn = fdiv_set_company_kbn_array();

	//ラジオボタン設定
	fdiv_set_company_kbn_radio($gc, $gc->company_kbn, "company_kbn");

	//チェックボックス設定
	fdiv_set_checkbox($gc, "リロケーション", ($gc->relocation_flg=="1"), "relocation_flg");

	if(is_numeric($gc->company_no)){
		$gc->joken_company_nm = fdb_get_name($gc, "m_company", "company_nm", "company_no", $gc->company_no);
	}
	if($gc->joken_company_nm==""){
		$gc->joken_company_nm = "指定なし";
	}

	if($gc->company_sh==""){
		$gc->joken_company_sh = "指定なし";
	}else{
		$gc->joken_company_sh = $gc->company_sh;
	}

	if(is_numeric($gc->todoufuken_no)){
		$gc->joken_todoufuken_nm = $arr_todoufuken[$gc->todoufuken_no];
	}
	if($gc->joken_todoufuken_nm==""){
		$gc->joken_todoufuken_nm = "指定なし";
	}

	if($gc->relocation_flg=="1"){
		$gc->joken_relocation_flg_nm = "あり";
	}else{
		$gc->joken_relocation_flg_nm = "指定なし";
	}

	if(is_numeric($gc->company_kbn)){
		if($gc->company_kbn > 0){
			$gc->joken_company_kbn_nm = $arr_company_kbn[$gc->company_kbn];
		}else{
			$gc->joken_company_kbn_nm = "全て";
		}
	}else{
		$gc->joken_company_kbn_nm = "指定なし";
	}

	//ベースSQLの作成
	$base_sql = sql_text_create_l($gc);

	//手数料合計の取得
/*
	$sql = "SELECT";
	$sql.= " COALESCE(rl.sum_tesuryou, 0) AS sum_tesuryou_l,";
	$sql.= " COALESCE(rs.sum_tesuryou, 0) AS sum_tesuryou_s,";
	$sql.= " COALESCE(ra.sum_tesuryou, 0) AS sum_tesuryou_a,";
	$sql.= " COALESCE(rb.sum_tesuryou, 0) AS sum_tesuryou_b,";
	$sql.= " COALESCE(rc.sum_tesuryou, 0) AS sum_tesuryou_c ";
	$sql.= $base_sql;

	$rs = $gc->db->query($sql);

	$gc->sum_tesuryou = 0;

	while ($rs->eof==false) {

		$sum_tesuryou_l = $rs->fields["sum_tesuryou_l"];
		$sum_tesuryou_s = $rs->fields["sum_tesuryou_s"];
		$sum_tesuryou_a = $rs->fields["sum_tesuryou_a"];
		$sum_tesuryou_b = $rs->fields["sum_tesuryou_b"];
		$sum_tesuryou_c = $rs->fields["sum_tesuryou_c"];

		$gc->sum_tesuryou += $sum_tesuryou_l + $sum_tesuryou_s + $sum_tesuryou_a + $sum_tesuryou_b + $sum_tesuryou_c;

		$rs->move_next();

	}
	$rs->free_result();
	$sql = "SELECT SQL_CALC_FOUND_ROWS";
	$sql.= " mc.company_no,";
	$sql.= " mc.company_nm,";
	$sql.= " mc.company_kn,";
	$sql.= " mc.company_sh,";
	$sql.= " mc.company_kbn,";
	$sql.= " mc.todoufuken_no,";
	$sql.= " mc.add1,";
	$sql.= " mc.jyougen,";
	$sql.= " COALESCE(rl.cnt_rank, 0) AS cnt_rank_l,";
	$sql.= " COALESCE(rl.sum_tesuryou, 0) AS sum_tesuryou_l,";
	$sql.= " COALESCE(rs.cnt_rank, 0) AS cnt_rank_s,";
	$sql.= " COALESCE(rs.sum_tesuryou, 0) AS sum_tesuryou_s,";
	$sql.= " COALESCE(ra.cnt_rank, 0) AS cnt_rank_a,";
	$sql.= " COALESCE(ra.sum_tesuryou, 0) AS sum_tesuryou_a,";
	$sql.= " COALESCE(rb.cnt_rank, 0) AS cnt_rank_b,";
	$sql.= " COALESCE(rb.sum_tesuryou, 0) AS sum_tesuryou_b,";
	$sql.= " COALESCE(rc.cnt_rank, 0) AS cnt_rank_c,";
	$sql.= " COALESCE(rc.sum_tesuryou, 0) AS sum_tesuryou_c ";
	$sql.= $base_sql;
*/
	$sql= $base_sql;

	$sql.= " ORDER BY";

	switch($_GET["si"]) {
	case "ckn":
		$sql.= " c.company_kn".(($_GET["sa"]=="desc") ? " DESC" : "")." ";
		break;
	case "kbn":
		$sql.= " c.company_kbn".(($_GET["sa"]=="desc") ? " DESC" : "")." ";
		break;
	case "tod":
		$sql.= " c.todoufuken_no".(($_GET["sa"]=="desc") ? " DESC" : "")." ";
		break;
	case "crl":
		$sql.= " sr_l".(($_GET["sa"]=="desc") ? " DESC" : "")." ";
		break;
	case "crs":
		$sql.= " sr_1".(($_GET["sa"]=="desc") ? " DESC" : "")." ";
		break;
	case "cra":
		$sql.= " sr_2".(($_GET["sa"]=="desc") ? " DESC" : "")." ";
		break;
	case "crb":
		$sql.= " sr_3".(($_GET["sa"]=="desc") ? " DESC" : "")." ";
		break;
	case "crc":
		$sql.= " sr_4".(($_GET["sa"]=="desc") ? " DESC" : "")." ";
		break;
	case "tes":
		$sql.= " s_t".(($_GET["sa"]=="desc") ? " DESC" : "")." ";
		break;
	case "jog":
		$sql.= " c.jyougen".(($_GET["sa"]=="desc") ? " DESC" : "")." ";
		break;
	default:
		$sql.= " c.company_no ";
	}

	$sql.= f_get_limit($gc->pn, $gc->pl, C_ORDER_LIST_COL_CNT);

	$rs = $gc->db->query($sql);

	$row_count = $gc->db->get_row_count();

	//ページャーの設定
	if($row_count > 0){
		$page_arr = f_page_arr("tesuryo_l.php", $row_count, $gc->pl, C_ORDER_LIST_COL_CNT, C_ORDER_PAGE_TAG_CNT);
	}

	//ソート関連
	$sort_mode["ckn"] = "";
	$sort_mode["kbn"] = "";
	$sort_mode["tod"] = "";
	$sort_mode["crl"] = "";
	$sort_mode["crs"] = "";
	$sort_mode["cra"] = "";
	$sort_mode["crb"] = "";
	$sort_mode["crc"] = "";
	$sort_mode["tes"] = "";
	$sort_mode["jog"] = "";

	foreach ($sort_mode as $key => &$value) {
		if($key == $_GET["si"]){
			if($_GET["sa"] == "desc"){
				$value = " ▼";
			}else{
				$value = " ▲";
			}
		}
	}

?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>手数料一覧</title>
<!-- *** stylesheet *** -->
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<!-- *** javascript *** -->
<script type="text/javascript" src="js/listpage.js" charset="utf-8"></script>
<script language="JavaScript">
<!--
var submit_flg = false;
function run_submit(fname, mode) {
	document.forms[fname].mode.value = mode;
	if(submit_flg==false){
		//ボタン2度押し対応
		submit_flg = true;
		document.forms[fname].submit();
	}
}
function unload_page(){
	submit_flg = false;
}
window.onunload = unload_page;
function search_run(){
	var o;
	o = document.getElementById('mbif_y');
	var mbif_y = o.options[ o.selectedIndex ].value;
	o = document.getElementById('mbif_m');
	var mbif_m = o.options[ o.selectedIndex ].value;
	o = document.getElementById('mbif_d');
	var mbif_d = o.options[ o.selectedIndex ].value;
	o = document.getElementById('mbit_y');
	var mbit_y = o.options[ o.selectedIndex ].value;
	o = document.getElementById('mbit_m');
	var mbit_m = o.options[ o.selectedIndex ].value;
	o = document.getElementById('mbit_d');
	var mbit_d = o.options[ o.selectedIndex ].value;
	document.forms['form_search'].mbif.value = mbif_y + mbif_m + mbif_d;
	document.forms['form_search'].mbit.value = mbit_y + mbit_m + mbit_d;
	run_submit('form_search', 'search');
}
// -->
</script>
</head>
<body>

<!-- Header -->
<div id="header">
	<div class="shell">
		<!-- Logo + Top Nav -->
		<?php tcom_header_logo_nav($gc) ?>
		<!-- End Logo + Top Nav -->
		<!-- Main Nav -->
		<?php tcom_header_main_nav2($gc, 2) ?>
		<!-- End Main Nav -->
	</div>
</div>
<!-- End Header -->

<!-- Container -->
<div id="container">
	<div class="shell">

		<!-- Small Nav -->
		<div class="small-nav">
			<a href="tesuryo_l.php">手数料管理</a>
			<span>&gt;</span>
			手数料一覧
		</div>
		<!-- End Small Nav -->

		<!-- Main -->
		<div id="main">
			<div class="cl">&nbsp;</div>

			<!-- Content -->
			<div id="content">

				<!-- Box -->
				<div class="box">

					<!-- Form -->
					<div class="form">

						<form name="form_search" action="tesuryo_l.php" method="get" onsubmit="return false">
							<input name="mode" type="hidden" value="">
							<input name="mbif" type="hidden" value="">
							<input name="mbit" type="hidden" value="">

							<div class="box-size4 left">
								<p class="inline-field">
									<label style="display:inline;">集計期間:</label>
									<select id="mbif_y" class="field">
										<?php echo fsel_get_date_y($gc, $gc->mbif_y) ?>
									</select><span class="ml05">年</span>
									<select id="mbif_m" class="field">
										<?php echo fsel_get_date_m($gc, $gc->mbif_m) ?>
									</select><span class="ml05">月</span>
									<select id="mbif_d" class="field">
										<?php echo fsel_get_date_d($gc, $gc->mbif_d) ?>
									</select><span class="ml05">日</span>
									~
									<select id="mbit_y" class="field">
										<?php echo fsel_get_date_y($gc, $gc->mbit_y) ?>
									</select><span class="ml05">年</span>
									<select id="mbit_m" class="field">
										<?php echo fsel_get_date_m($gc, $gc->mbit_m) ?>
									</select><span class="ml05">月</span>
									<select id="mbit_d" class="field">
										<?php echo fsel_get_date_d($gc, $gc->mbit_d) ?>
									</select><span class="ml05">日</span>

									<label class="ml20" style="display:inline;">区分:</label>
									<input id="company_kbn_0" type="radio" name="company_kbn" value="0"<?php echo $gc->company_kbn_0_checked ?> />
									<label class="mr10" for="company_kbn_0" style="display:inline;font-weight: normal;">全て</label>
									<input id="company_kbn_1" type="radio" name="company_kbn" value="1"<?php echo $gc->company_kbn_1_checked ?> />
									<label class="mr10" for="company_kbn_1" style="display:inline;font-weight: normal;">大手</label>
									<input id="company_kbn_2" type="radio" name="company_kbn" value="2"<?php echo $gc->company_kbn_2_checked ?> />
									<label class="mr10" for="company_kbn_2" style="display:inline;font-weight: normal;">地場</label>

								</p>
							</div>

							<div class="box-size4 left">
								<p class="inline-field">
									<label style="display:inline;">提携会社:</label>
									<select name="company_no" class="field">
										<option value=""></option>
										<?php echo fsel_get_company($gc, $gc->company_no) ?>
									</select>

									<label class="ml05" style="display:inline;">支店名:</label>
									<input name="company_sh" type="text" class="field size2" value="<?php echo f_hsc($gc->company_sh)?>" />

									<label class="ml05" style="display:inline;">所在地:</label>
									<select name="todoufuken_no" class="field">
										<option value=""></option>
										<?php echo fsel_get_todoufuken($gc, $gc->todoufuken_no) ?>
									</select>

									<label class="ml15" style="display:inline;">
										<input type="checkbox" name="relocation_flg" id="relocation_flg" value="1"<?php echo $gc->relocation_flg_checked?>>
										<span style="color:#000;">リロケーション</span>
									</label>

									<button type="button" class="button color silver ml30" onclick="search_run();">検索</button>
								</p>
							</div>

							<div class="cl">&nbsp;</div>

						</form>

					</div>
					<!-- End Form -->

					<!-- Box Head -->
					<div class="box-head">
						<h2 class="left">抽出条件・手数料合計</h2>
						<div class="right">
							<div class="cl">&nbsp;</div>
						</div>
					</div>
					<!-- End Box Head -->

					<!-- Form -->
					<div class="form">

						<div class="box-size4 left">
							<p class="inline-field">
								<label style="display:inline;">集計期間:</label>
								<?php echo substr($gc->mbif, 0, 4) ?>年<?php echo substr($gc->mbif, 4, 2) ?>月<?php echo substr($gc->mbif, 6, 2) ?>日
								~
								<?php echo substr($gc->mbit, 0, 4) ?>年<?php echo substr($gc->mbit, 4, 2) ?>月<?php echo substr($gc->mbit, 6, 2) ?>日
								<label class="ml20" style="display:inline;">区分:</label>
								<?php echo f_hsc($gc->joken_company_kbn_nm) ?>
							</p>
						</div>
						<div class="box-size4 left">
							<p class="inline-field">
								<label style="display:inline;">提携会社:</label>
								<?php echo f_hsc($gc->joken_company_nm) ?>
								<label class="ml20" style="display:inline;">支店名:</label>
								<?php echo f_hsc($gc->joken_company_sh) ?>
								<label class="ml20" style="display:inline;">所在地:</label>
								<?php echo f_hsc($gc->joken_todoufuken_nm) ?>
								<label class="ml20" style="display:inline;">リロケーション:</label>
								<?php echo f_hsc($gc->joken_relocation_flg_nm) ?>
							</p>
						</div>

						<div style="float:right;">
							<label class="ml40" style="display:inline;">手数料合計:</label>
							<?php echo number_format($gc->sum_tesuryou) ?>円
						</div>

						<div class="cl">&nbsp;</div>

					</div>
					<!-- End Form -->

					<!-- Box Head -->
					<div class="box-head">
						<h2 class="left">手数料一覧</h2>
						<div class="right">
							<a href="tesuryo_csv.php?mode=1&mbif=<?php echo f_hsc($gc->mbif) ?>&mbit=<?php echo f_hsc($gc->mbit) ?>&todoufuken_no=<?php echo f_hsc($gc->todoufuken_no) ?>&company_no=<?php echo f_hsc($gc->company_no) ?>&company_kbn=<?php echo f_hsc($gc->company_kbn) ?>&relocation_flg=<?php echo f_hsc($gc->relocation_flg) ?>&company_sh=<?php echo urlencode($gc->company_sh) ?>" class="custom-button"><span>CSV出力</span></a>
						</div>
					</div>
					<!-- End Box Head -->

					<!-- Table -->
					<div class="table">

<?php if($row_count > 0){ ?>
						<!-- Pagging -->
						<div class="pagging">
							<div class="box-l">
								<?php echo $page_arr["cmes_str"].$page_arr["par1_str"].$page_arr["par2_str"]; ?>
							</div>
							<div class="box-c">
								<div class="margin-center">
									<?php echo $page_arr["back_str"].$page_arr["list_str"].$page_arr["deno_str"].$page_arr["next_str"]; ?>
								</div>
							</div>
							<div class="box-r">
								<label>表示件数:</label>
								<?php echo $page_arr["plst_str"] ?>
							</div>
						</div>
						<!-- End Pagging -->
<?php } ?>

						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr style="border-top:solid 1px #e0e0e0;">

								<th width="200" class="ac"><a href="tesuryo_l.php<?php echo f_sq("ckn") ?>">提携会社名</a><?php echo $sort_mode["ckn"] ?></th>
								<th width="40" class="ac"><a href="tesuryo_l.php<?php echo f_sq("kbn") ?>">区分</a><?php echo $sort_mode["kbn"] ?></th>
								<th class="ac"><a href="tesuryo_l.php<?php echo f_sq("tod") ?>">所在地</a><?php echo $sort_mode["tod"] ?></th>
								<th width="44" class="ac"><a href="tesuryo_l.php<?php echo f_sq("crl") ?>">Lプラン</a><?php echo $sort_mode["crl"] ?><br />(件数)</th>
								<th width="44" class="ac"><a href="tesuryo_l.php<?php echo f_sq("crs") ?>">Sランク</a><?php echo $sort_mode["crs"] ?><br />(件数)</th>
								<th width="44" class="ac"><a href="tesuryo_l.php<?php echo f_sq("cra") ?>">Aランク</a><?php echo $sort_mode["cra"] ?><br />(件数)</th>
								<th width="44" class="ac"><a href="tesuryo_l.php<?php echo f_sq("crb") ?>">Bランク</a><?php echo $sort_mode["crb"] ?><br />(件数)</th>
								<th width="44" class="ac"><a href="tesuryo_l.php<?php echo f_sq("crc") ?>">Cランク</a><?php echo $sort_mode["crc"] ?><br />(件数)</th>
								<th width="70" class="ac"><a href="tesuryo_l.php<?php echo f_sq("tes") ?>">手数料</a><?php echo $sort_mode["tes"] ?></th>
								<th width="70" class="ac"><a href="tesuryo_l.php<?php echo f_sq("jog") ?>">上限</a><?php echo $sort_mode["jog"] ?></th>
								<th width="60" class="ac">詳細</th>
							</tr>

<?php

	$i = 0;

	while ($rs->eof==false) {

		$company_no = $rs->fields["company_no"];
		$company_nm = $rs->fields["company_nm"];
		$company_sh = $rs->fields["company_sh"];
		$company_kbn = $rs->fields["company_kbn"];
		$todoufuken_no = $rs->fields["todoufuken_no"];
		$add1 = $rs->fields["add1"];
		$rank_l = $rs->fields["sr_l"];
		$rank_no1 = $rs->fields["sr_1"];
		$rank_no2 = $rs->fields["sr_2"];
		$rank_no3 = $rs->fields["sr_3"];
		$rank_no4 = $rs->fields["sr_4"];
		$sum_tesuryou_l = $rs->fields["sum_tesuryou_l"];
		$sum_tesuryou_s = $rs->fields["sum_tesuryou_s"];
		$sum_tesuryou_a = $rs->fields["sum_tesuryou_a"];
		$sum_tesuryou_b = $rs->fields["sum_tesuryou_b"];
		$sum_tesuryou_c = $rs->fields["sum_tesuryou_c"];
		$jyougen = $rs->fields["jyougen"];

		$todoufuken_nm = $arr_todoufuken[$todoufuken_no];

		$company_kbn_nm = $arr_company_kbn[$company_kbn];


		$tesuryou =$rs->fields["s_t"];
//		$tesuryou =$sum_tesuryou_l + $sum_tesuryou_s + $sum_tesuryou_a + $sum_tesuryou_b + $sum_tesuryou_c;

		$odd = "";
		if(($i % 2)==1){
			$odd = " class=\"odd\"";
		}

		echo "<tr".$odd.">";
		echo "<td>".f_hsc($company_nm)."<br />".f_hsc($company_sh)."</td>";
		echo "<td class=\"ac\">".f_hsc($company_kbn_nm)."</td>";
		echo "<td>".f_hsc($todoufuken_nm.$add1)."</td>";
		echo "<td class=\"ac\">".f_hsc($rank_l)."</td>";
		echo "<td class=\"ac\">".f_hsc($rank_no1)."</td>";
		echo "<td class=\"ac\">".f_hsc($rank_no2)."</td>";
		echo "<td class=\"ac\">".f_hsc($rank_no3)."</td>";
		echo "<td class=\"ac\">".f_hsc($rank_no4)."</td>";
		echo "<td class=\"ar\">".f_hsc(number_format($tesuryou))."</td>";
		echo "<td class=\"ar\">".f_hsc(number_format($jyougen))."</td>";
		echo "<td class=\"ac\"><button type=\"button\" class=\"list-button\" onclick=\"location.href='tesuryo_d.php?company_no=".$company_no."&mbif=".$gc->mbif."&mbit=".$gc->mbit."';\">詳細</button></td>";
		echo "</tr>";

		$rs->move_next();

		$i++;

	}

	$rs->free_result();

	if($row_count==0){
		echo "<tr>";
		echo "<td colspan=\"10\" align=\"center\">データはありません。</td>";
		echo "</tr>";
	}

?>

						</table>

<?php if($row_count > 0){ ?>
						<!-- Pagging -->
						<div class="pagging">
							<div class="box-l">
								&nbsp;
							</div>
							<div class="box-c">
								<div class="margin-center">
									<?php echo $page_arr["back_str"].$page_arr["list_str"].$page_arr["deno_str"].$page_arr["next_str"]; ?>
								</div>
							</div>
							<div class="box-r">
								<label>表示件数:</label>
								<?php echo $page_arr["plst_str"] ?>
							</div>
						</div>
						<!-- End Pagging -->
<?php } ?>

					</div>
					<!-- Table -->

				</div>
				<!-- End Box -->
				<div class="cl">&nbsp;</div>

			</div>
			<!-- End Content -->
			<div class="cl">&nbsp;</div>

		</div>
		<!-- Main -->
	</div>
</div>
<!-- End Container -->

<!-- Footer -->
	<?php tcom_footer($gc) ?>
<!-- End Footer -->

</body>
</html>
<?php
}
示例#2
0
function download_csv_file1($gc) {

	$crlf = "\r\n";

	$arr_todoufuken = fsel_get_arr_todoufuken($gc);

	$rank = fdiv_set_rank_array();

	$file_str = "";

	unset($line);

	$line[] = csv_item_edit("提携会社名");
	$line[] = csv_item_edit("区分");
	$line[] = csv_item_edit("所在地");
	$line[] = csv_item_edit("Lランク(件数)");
	$line[] = csv_item_edit("Sランク(件数)");
	$line[] = csv_item_edit("Aランク(件数)");
	$line[] = csv_item_edit("Bランク(件数)");
	$line[] = csv_item_edit("Cランク(件数)");
	$line[] = csv_item_edit("手数料");
	$line[] = csv_item_edit("上限");

	$file_str.= implode(",", $line).$crlf;

	/////////////////////////////////////////////////////////////

	$arr_company_kbn = fdiv_set_company_kbn_array();

	$gc->mbif = $_GET["mbif"];
	$y = substr($gc->mbif, 0, 4);
	$m = substr($gc->mbif, 4, 2);
	$d = substr($gc->mbif, 6, 2);
	if(!@checkdate($m, $d, $y)){
		$gc->mbif = date("Ym01", time());
	}

	$gc->mbit = $_GET["mbit"];
	$y = substr($gc->mbit, 0, 4);
	$m = substr($gc->mbit, 4, 2);
	$d = substr($gc->mbit, 6, 2);
	if(!@checkdate($m, $d, $y)){
		$gc->mbit = date("Ymt", time());
	}

	$gc->company_sh = $_GET["company_sh"];
	$gc->todoufuken_no = $_GET["todoufuken_no"];
	$gc->company_no = $_GET["company_no"];
	$gc->company_kbn = $_GET["company_kbn"];
	$gc->relocation_flg = $_GET["relocation_flg"];

	//ベースSQLの作成
	$base_sql = sql_text_create_l($gc);

/*
	$base_sql = "";
	$base_sql.= "FROM";
	$base_sql.= " m_company mc ";

	$base_sql.= "LEFT JOIN";
	$base_sql.= " (SELECT";
	$base_sql.= "   ic.company_no,";
	$base_sql.= "   COUNT(*) AS cnt_rank,";
	$base_sql.= "   SUM(ti.tesuryou) AS sum_tesuryou";
	$base_sql.= "  FROM";
	$base_sql.= "   t_item ti";
	$base_sql.= "  INNER JOIN";
	$base_sql.= "   t_item_company ic";
	$base_sql.= "  ON";
	$base_sql.= "   ti.item_no = ic.item_no";
	$base_sql.= "  WHERE";
	$base_sql.= "   ti.mukou_flg = 0 AND";
	$base_sql.= "   ti.purpose_flg = 1 AND";
	$base_sql.= "   DATE_FORMAT(ti.moushikomibi,'%Y%m%d') BETWEEN '".$gc->mbif."' AND '".$gc->mbit."'";
	$base_sql.= "  GROUP BY";
	$base_sql.= "   ic.company_no";
	$base_sql.= " ) rl ";
	$base_sql.= "ON";
	$base_sql.= " mc.company_no = rl.company_no ";

	$base_sql.= "LEFT JOIN";
	$base_sql.= " (SELECT";
	$base_sql.= "   ic.company_no,";
	$base_sql.= "   COUNT(*) AS cnt_rank,";
	$base_sql.= "   SUM(ti.tesuryou) AS sum_tesuryou";
	$base_sql.= "  FROM";
	$base_sql.= "   t_item ti";
	$base_sql.= "  INNER JOIN";
	$base_sql.= "   t_item_company ic";
	$base_sql.= "  ON";
	$base_sql.= "   ti.item_no = ic.item_no";
	$base_sql.= "  WHERE";
	$base_sql.= "   ti.mukou_flg = 0 AND";
	$base_sql.= "   ti.rank_no = 1 AND";
	$base_sql.= "   ti.purpose_flg != 1 AND";
	$base_sql.= "   DATE_FORMAT(ti.moushikomibi,'%Y%m%d') BETWEEN '".$gc->mbif."' AND '".$gc->mbit."'";
	$base_sql.= "  GROUP BY";
	$base_sql.= "   ic.company_no";
	$base_sql.= " ) rs ";
	$base_sql.= "ON";
	$base_sql.= " mc.company_no = rs.company_no ";
	$base_sql.= "LEFT JOIN";
	$base_sql.= " (SELECT";
	$base_sql.= "   ic.company_no,";
	$base_sql.= "   COUNT(*) AS cnt_rank,";
	$base_sql.= "   SUM(ti.tesuryou) AS sum_tesuryou";
	$base_sql.= "  FROM";
	$base_sql.= "   t_item ti";
	$base_sql.= "  INNER JOIN";
	$base_sql.= "   t_item_company ic";
	$base_sql.= "  ON";
	$base_sql.= "   ti.item_no = ic.item_no";
	$base_sql.= "  WHERE";
	$base_sql.= "   ti.mukou_flg = 0 AND";
	$base_sql.= "   ti.rank_no = 2 AND";
	$base_sql.= "   ti.purpose_flg != 1 AND";
	$base_sql.= "   DATE_FORMAT(ti.moushikomibi,'%Y%m%d') BETWEEN '".$gc->mbif."' AND '".$gc->mbit."'";
	$base_sql.= "  GROUP BY";
	$base_sql.= "   ic.company_no";
	$base_sql.= " ) ra ";
	$base_sql.= "ON";
	$base_sql.= " mc.company_no = ra.company_no ";
	$base_sql.= "LEFT JOIN";
	$base_sql.= " (SELECT";
	$base_sql.= "   ic.company_no,";
	$base_sql.= "   COUNT(*) AS cnt_rank,";
	$base_sql.= "   SUM(ti.tesuryou) AS sum_tesuryou";
	$base_sql.= "  FROM";
	$base_sql.= "   t_item ti";
	$base_sql.= "  INNER JOIN";
	$base_sql.= "   t_item_company ic";
	$base_sql.= "  ON";
	$base_sql.= "   ti.item_no = ic.item_no";
	$base_sql.= "  WHERE";
	$base_sql.= "   ti.mukou_flg = 0 AND";
	$base_sql.= "   ti.rank_no = 3 AND";
	$base_sql.= "   ti.purpose_flg != 1 AND";
	$base_sql.= "   DATE_FORMAT(ti.moushikomibi,'%Y%m%d') BETWEEN '".$gc->mbif."' AND '".$gc->mbit."'";
	$base_sql.= "  GROUP BY";
	$base_sql.= "   ic.company_no";
	$base_sql.= " ) rb ";
	$base_sql.= "ON";
	$base_sql.= " mc.company_no = rb.company_no ";
	$base_sql.= "LEFT JOIN";
	$base_sql.= " (SELECT";
	$base_sql.= "   ic.company_no,";
	$base_sql.= "   COUNT(*) AS cnt_rank,";
	$base_sql.= "   SUM(ti.tesuryou) AS sum_tesuryou";
	$base_sql.= "  FROM";
	$base_sql.= "   t_item ti";
	$base_sql.= "  INNER JOIN";
	$base_sql.= "   t_item_company ic";
	$base_sql.= "  ON";
	$base_sql.= "   ti.item_no = ic.item_no";
	$base_sql.= "  WHERE";
	$base_sql.= "   ti.mukou_flg = 0 AND";
	$base_sql.= "   ti.rank_no = 4 AND";
	$base_sql.= "   ti.purpose_flg != 1 AND";
	$base_sql.= "   DATE_FORMAT(ti.moushikomibi,'%Y%m%d') BETWEEN '".$gc->mbif."' AND '".$gc->mbit."'";
	$base_sql.= "  GROUP BY";
	$base_sql.= "   ic.company_no";
	$base_sql.= " ) rc ";
	$base_sql.= "ON";
	$base_sql.= " mc.company_no = rc.company_no ";
	$base_sql.= "INNER JOIN";
	$base_sql.= " (SELECT";
	$base_sql.= "   ic.company_no";
	$base_sql.= "  FROM";
	$base_sql.= "   t_item ti";
	$base_sql.= "  INNER JOIN";
	$base_sql.= "   t_item_company ic";
	$base_sql.= "  ON";
	$base_sql.= "   ti.item_no = ic.item_no";
	$base_sql.= "  WHERE";
	$base_sql.= "   DATE_FORMAT(ti.moushikomibi,'%Y%m%d') BETWEEN '".$gc->mbif."' AND '".$gc->mbit."'";
	$base_sql.= "  GROUP BY";
	$base_sql.= "   ic.company_no";
	$base_sql.= " ) tic ";
	$base_sql.= "ON";
	$base_sql.= " mc.company_no = tic.company_no ";

	$base_sql.= "WHERE 0 = 0 ";

	if($gc->relocation_flg==1){
		$base_sql.= " AND mc.relocation_flg = 1 ";
	}

	switch ($gc->company_kbn) {
	case 1://大手
		$base_sql.= "AND mc.company_kbn = 1 ";
		break;
	case 2://地場
		$base_sql.= "AND mc.company_kbn = 2 ";
		break;
	}

	if(is_numeric($gc->company_no)){
		$base_sql.= "AND mc.company_no = ".$gc->company_no." ";
	}

	if(strlen($gc->company_sh) > 0) {
		$base_sql.= "AND mc.company_sh = '".f_dbs($gc->company_sh)."' ";
	}

	if(is_numeric($gc->todoufuken_no)){
		$base_sql.= "AND mc.todoufuken_no = ".$gc->todoufuken_no." ";
	}


	//手数料合計の取得

	$sql = "SELECT SQL_CALC_FOUND_ROWS";
	$sql.= " mc.company_no,";
	$sql.= " mc.company_nm,";
	$sql.= " mc.company_kn,";
	$sql.= " mc.company_sh,";
	$sql.= " mc.company_kbn,";
	$sql.= " mc.todoufuken_no,";
	$sql.= " mc.add1,";
	$sql.= " mc.jyougen,";
	$sql.= " COALESCE(rl.cnt_rank, 0) AS cnt_rank_l,";
	$sql.= " COALESCE(rl.sum_tesuryou, 0) AS sum_tesuryou_l,";
	$sql.= " COALESCE(rs.cnt_rank, 0) AS cnt_rank_s,";
	$sql.= " COALESCE(rs.sum_tesuryou, 0) AS sum_tesuryou_s,";
	$sql.= " COALESCE(ra.cnt_rank, 0) AS cnt_rank_a,";
	$sql.= " COALESCE(ra.sum_tesuryou, 0) AS sum_tesuryou_a,";
	$sql.= " COALESCE(rb.cnt_rank, 0) AS cnt_rank_b,";
	$sql.= " COALESCE(rb.sum_tesuryou, 0) AS sum_tesuryou_b,";
	$sql.= " COALESCE(rc.cnt_rank, 0) AS cnt_rank_c,";
	$sql.= " COALESCE(rc.sum_tesuryou, 0) AS sum_tesuryou_c ";
	$sql.= $base_sql;
	$sql.= "ORDER BY";

	$sql.= " mc.company_no";

*/
	$sql= $base_sql;

	$rs = $gc->db->query($sql);

	$row_count = $gc->db->get_row_count();

	$i = 0;

	while ($rs->eof==false) {

		unset($line);

		$company_no = $rs->fields["company_no"];
		$company_nm = $rs->fields["company_nm"];
		$company_sh = $rs->fields["company_sh"];
		$company_kbn = $rs->fields["company_kbn"];
		$todoufuken_no = $rs->fields["todoufuken_no"];
		$add1 = $rs->fields["add1"];
		$rank_l = $rs->fields["sr_l"];
		$rank_no1 = $rs->fields["sr_1"];
		$rank_no2 = $rs->fields["sr_2"];
		$rank_no3 = $rs->fields["sr_3"];
		$rank_no4 = $rs->fields["sr_4"];
		$sum_tesuryou_l = $rs->fields["sum_tesuryou_l"];
		$sum_tesuryou_s = $rs->fields["sum_tesuryou_s"];
		$sum_tesuryou_a = $rs->fields["sum_tesuryou_a"];
		$sum_tesuryou_b = $rs->fields["sum_tesuryou_b"];
		$sum_tesuryou_c = $rs->fields["sum_tesuryou_c"];
		$jyougen = $rs->fields["jyougen"];


		$todoufuken_nm = $arr_todoufuken[$todoufuken_no];

		$company_kbn_nm = $arr_company_kbn[$company_kbn];

		$tesuryou =$rs->fields["s_t"];
//		$tesuryou =$sum_tesuryou_l + $sum_tesuryou_s + $sum_tesuryou_a + $sum_tesuryou_b + $sum_tesuryou_c;

		$line[] = csv_item_edit($company_nm.$company_sh);
		$line[] = csv_item_edit($company_kbn_nm);
		$line[] = csv_item_edit($todoufuken_nm.$add1);
		$line[] = csv_item_edit($rank_l);
		$line[] = csv_item_edit($rank_no1);
		$line[] = csv_item_edit($rank_no2);
		$line[] = csv_item_edit($rank_no3);
		$line[] = csv_item_edit($rank_no4);
		$line[] = csv_item_edit(number_format($tesuryou));
		$line[] = csv_item_edit(number_format($jyougen));

		$file_str.= implode(",", $line).$crlf;

		$rs->move_next();

		$i++;

	}

	$rs->free_result();

	$file_str = mb_convert_encoding($file_str, "sjis-win", C_ENCODING);

	$file_length = strlen($file_str);

	$file_name = "手数料(".substr($gc->mbif, 0, 4)."年".substr($gc->mbif, 4, 2)."月".substr($gc->mbif, 6, 2)."日から".substr($gc->mbit, 0, 4)."年".substr($gc->mbit, 4, 2)."月".substr($gc->mbit, 6, 2).").csv";
	$agent = $_SERVER['HTTP_USER_AGENT'];
	if(strstr($agent, "MSIE")){
		$file_name = urlencode($file_name);
	}

	header("Content-Disposition: attachment; filename=".$file_name);
	header("Content-Length:".$file_length);
	header("Content-Type: application/octet-stream");

	echo $file_str;

	return true;

}