<?php

include_once($_SERVER['DOCUMENT_ROOT'] . '/lib/config.php');

$sys = new System();

// パラメータ
$rtn		= array();
$rs			= null;
$row		= null;
$currencies	= null;
$list		= array();
$pId		= $sys -> getDataPost(PARAM_P_ID);
$agentCode	= $sys -> getDataPost(PARAM_AGENT_CODE);

$currencies	= $sys -> getExchangeFeeCommon($pId);
$rs			= $sys -> accessSelect('LIST_COMMISION_EXCHANGE', array($agentCode));

// データの存在確認
if($sys -> isLoopData($rs)) {
	foreach($rs as $row) {
		$list[$sys -> getColumnData($row, COLUMN_FROM_CURRENCY) . $sys -> getColumnData($row, COLUMN_TO_CURRENCY)] = $row;
	}
}

// データが存在する場合
if($sys -> isLoopData($currencies)) {

	// 各通貨のレートを設定する
	foreach($currencies as $key => $val) {

		// From通貨
		$from = $key;

		foreach($val as $keySub => $valSub){

			// From通貨
			$to = $keySub;

			// 行データの取得
			$row = $sys -> getColumnData($list, $from . $to);

			// 卸値の取得
			$rtn['share_' . $from . DELIMIT_UNDER_BAR . $to] = $sys -> intToCurrency(intval($sys -> getColumnData($row, COLUMN_PERCENT)), PERCENT);

			// マークアップの取得
			$rtn['bottom_' . $from . DELIMIT_UNDER_BAR . $to] = $sys -> intToCurrency(intval($sys -> getColumnData($row, COLUMN_CHILDREN_PERCENT)), PERCENT);
		}
	}
}

echo json_encode($rtn);
?>
